feat(api): implement authenticated habit tracking and combined calendars
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { createHabitRoutes } from "./habits/routes";
|
||||
import { ApiError } from "./habits/service";
|
||||
import { Hono } from "hono";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { createAuth, type AppDatabase, type AuthEnv } from "./auth";
|
||||
@@ -13,9 +15,11 @@ export function createApi(db: AppDatabase, config: AuthConfig, request?: FetchDi
|
||||
});
|
||||
app.route("/api/auth", auth.routes);
|
||||
app.get("/api/me", auth.requireAuth, c => c.json(c.get("user")));
|
||||
app.route("/api", createHabitRoutes(db, auth, now ?? Date.now));
|
||||
app.notFound(c => c.json({ error: "Not found" }, 404));
|
||||
app.onError((_error, c) => {
|
||||
c.header("Cache-Control", "no-store");
|
||||
if (_error instanceof ApiError) return c.json({ error: _error.message }, _error.status);
|
||||
return c.json({ error: "Internal server error" }, 500);
|
||||
});
|
||||
return app;
|
||||
|
||||
Reference in New Issue
Block a user