diff options
| author | Pinapelz <yukais@pinapelz.com> | 2025-09-03 21:16:16 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2025-09-03 21:16:16 -0700 |
| commit | c8bae6ab79a32da0fe745ebb9401e14f86c1f0d8 (patch) | |
| tree | c5647d3b8d575abaf6952d3d5a1294564c8b4dca /backend/src/routes | |
| parent | d0d4f579f53e4a9e19b825dd5a1bf84c7d9f89e4 (diff) | |
add admin role to user, return result in /me route
Diffstat (limited to 'backend/src/routes')
| -rw-r--r-- | backend/src/routes/auth.ts | 1 | ||||
| -rw-r--r-- | backend/src/routes/user.ts | 13 |
2 files changed, 11 insertions, 3 deletions
diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 4c6c374..f857dea 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -34,6 +34,7 @@ export const handleRegistration = async (req: express.Request, res: express.Resp password: hashedPassword, salt, email, + isAdmin: false } }); diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index a03ece0..7db25db 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -4,8 +4,15 @@ import { prisma } from '../config/db'; export const handleMeRoute = async (req: express.Request, res: express.Response) => { try { - const user = (req as any).user; - res.json(user); + if (!req.session.userId) { + return res.status(403).json({ error: 'Not Authenticated' }); + } + const user = await prisma.user.findUniqueOrThrow({ + where: { id: req.session.userId }, + select: { id: true, username: true, isAdmin: true } + }); + const isAdmin = user.id === 1 || user.isAdmin; + res.json({user, isAdmin}); } catch (error) { console.error('Me endpoint error:', error); res.status(500).json({ error: 'Internal server error' }); @@ -20,7 +27,7 @@ export const handleGetCurrentSession = async (req: express.Request, res: expres const user = await prisma.user.findUnique({ where: { id: req.session.userId }, - select: { id: true, username: true, email: true } + select: { id: true, username: true, isAdmin: true } }); if (!user) { |
