feat(auth): add Discord OAuth sign-in and user timezones
Add persistent user and session storage, protected profile requests, and React sign-in controls. Capture and preserve each user's timezone, and load development and production configuration before migrations and server startup.
This commit is contained in:
22
src/api.ts
Normal file
22
src/api.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Hono } from "hono";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { createAuth, type AppDatabase, type AuthEnv } from "./auth";
|
||||
import type { AuthConfig } from "./auth/config";
|
||||
import type { FetchDiscord } from "./auth/discord";
|
||||
|
||||
export function createApi(db: AppDatabase, config: AuthConfig, request?: FetchDiscord, now?: () => number) {
|
||||
const app = new Hono<AuthEnv>();
|
||||
const auth = createAuth(db, config, request, now);
|
||||
app.get("/api/health", c => {
|
||||
db.get(sql`SELECT 1`);
|
||||
return c.json({ status: "ok" });
|
||||
});
|
||||
app.route("/api/auth", auth.routes);
|
||||
app.get("/api/me", auth.requireAuth, c => c.json(c.get("user")));
|
||||
app.notFound(c => c.json({ error: "Not found" }, 404));
|
||||
app.onError((_error, c) => {
|
||||
c.header("Cache-Control", "no-store");
|
||||
return c.json({ error: "Internal server error" }, 500);
|
||||
});
|
||||
return app;
|
||||
}
|
||||
Reference in New Issue
Block a user