diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts index f517461..458dad0 100644 --- a/apps/api/src/server.ts +++ b/apps/api/src/server.ts @@ -63,14 +63,8 @@ const authPlugin = new Elysia({ name: "auth" }) authUser: { async resolve({ jwt, cookie: { auth } }) { const token = auth.value && await jwt.verify(auth.value); - if (!token || !token.sessionId || (token.role !== "user" && token.role !== "admin")) throw status(401, "Unauthorized"); - if (token.role === "user" && !token.accountId) throw status(401, "Unauthorized"); - - return { - sessionId: token.sessionId.toString(), - isAdmin: token.role === "admin", - accountId: token.role === "user" ? token.accountId!.toString() : null, - }; + if (!token || token.role !== "user" || !token.accountId || !token.sessionId) throw status(401, "Unauthorized"); + return { sessionId: token.sessionId.toString(), accountId: token.accountId.toString() }; } } }); @@ -456,7 +450,12 @@ export const app = new Elysia() // ACCOUNTS .group("/accounts", (app) => app - // Non-authenticated + .guard({ authUser: true }) + .get("/me/stats", async ({ accountId }) => { + const stats = await s.Accounts.stats(accountId); + if (!stats) throw new NotFoundError("Account stats not found"); + return stats; + }) .get("/:id/stats", async ({ params: { id } }) => { const stats = await s.Accounts.stats(id); if (!stats) throw new NotFoundError("Account stats not found"); @@ -464,7 +463,6 @@ export const app = new Elysia() }, { params: t.Object({ id: t.String() }) }) - // Authenticated .guard({ authAdmin: true }) .get("/:id", async ({ params: { id } }) => { const account = await s.Accounts.get(id);