feat(auth): add current user endpoint and enhance logout with session management

This commit is contained in:
ngc2207 2025-01-31 20:26:49 +08:00
parent 5bb77e4ad4
commit 5bd06bc58e

View File

@ -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 });
});