mirror of
https://gitlab.massbug.com/massbug/judge4c.git
synced 2025-07-04 15:22:25 +00:00
feat(auth): add current user endpoint and enhance logout with session management
This commit is contained in:
parent
5bb77e4ad4
commit
5bd06bc58e
@ -5,8 +5,14 @@ import { zValidator } from "@hono/zod-validator";
|
||||
import { createAdminClient } from "@/lib/appwrite";
|
||||
import { deleteCookie, setCookie } from "hono/cookie";
|
||||
import { loginSchema, registerSchema } from "../schema";
|
||||
import { sessionMiddleware } from "@/lib/session-middleware";
|
||||
|
||||
const app = new Hono()
|
||||
.get("/current", sessionMiddleware, (c) => {
|
||||
const user = c.get("user");
|
||||
|
||||
return c.json({ data: user });
|
||||
})
|
||||
.post("/login", zValidator("json", loginSchema), async (c) => {
|
||||
const { email, password } = c.req.valid("json");
|
||||
|
||||
@ -41,8 +47,11 @@ const app = new Hono()
|
||||
|
||||
return c.json({ success: true });
|
||||
})
|
||||
.post("/logout", (c) => {
|
||||
.post("/logout", sessionMiddleware, async (c) => {
|
||||
const account = c.get("account");
|
||||
|
||||
deleteCookie(c, AUTH_COOKIE);
|
||||
await account.deleteSession("current");
|
||||
|
||||
return c.json({ success: true });
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user