17 lines
498 B
TypeScript
17 lines
498 B
TypeScript
import { define } from "@/utils.ts";
|
|
import type { MeResponse } from "@/src/admin.ts";
|
|
import { authenticate, unauthorized } from "@/src/auth.ts";
|
|
import type { User } from "@/src/db.ts";
|
|
|
|
export const handler = define.handlers({
|
|
async GET(ctx) {
|
|
const user = await authenticate(ctx.req);
|
|
if (!user) {
|
|
return unauthorized();
|
|
}
|
|
|
|
const { name, admin } = user as Partial<User>;
|
|
return Response.json({ id: user.id, name: name ?? "", admin: admin === true } satisfies MeResponse);
|
|
},
|
|
});
|