From 5459ed0a1b30189b7ca89c3b3e1469fcc6b41b5d Mon Sep 17 00:00:00 2001 From: Guido X Jansen Date: Mon, 2 Mar 2026 07:43:54 +0100 Subject: [PATCH] feat(auth): include user role in session and me responses (#113) --- src/routes/auth.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/routes/auth.ts b/src/routes/auth.ts index 5f57fab..8b06a7c 100644 --- a/src/routes/auth.ts +++ b/src/routes/auth.ts @@ -261,9 +261,9 @@ export function authRoutes(oauthClient: NodeOAuthClient): FastifyPluginCallback maxAge: sessionTtl, }) - // Fetch profile data (displayName, avatarUrl) from users table + // Fetch profile data (displayName, avatarUrl, role) from users table const userRows = await app.db - .select({ displayName: users.displayName, avatarUrl: users.avatarUrl }) + .select({ displayName: users.displayName, avatarUrl: users.avatarUrl, role: users.role }) .from(users) .where(eq(users.did, session.did)) @@ -280,6 +280,7 @@ export function authRoutes(oauthClient: NodeOAuthClient): FastifyPluginCallback handle: session.handle, displayName: userRows[0]?.displayName ?? null, avatarUrl: userRows[0]?.avatarUrl ?? null, + role: userRows[0]?.role ?? 'user', crossPostScopesGranted: prefRows[0]?.crossPostScopesGranted ?? false, }) } catch (err: unknown) { @@ -329,9 +330,9 @@ export function authRoutes(oauthClient: NodeOAuthClient): FastifyPluginCallback return await reply.status(401).send({ error: 'Invalid or expired token' }) } - // Fetch profile data (displayName, avatarUrl) from users table + // Fetch profile data (displayName, avatarUrl, role) from users table const meUserRows = await app.db - .select({ displayName: users.displayName, avatarUrl: users.avatarUrl }) + .select({ displayName: users.displayName, avatarUrl: users.avatarUrl, role: users.role }) .from(users) .where(eq(users.did, session.did)) @@ -346,6 +347,7 @@ export function authRoutes(oauthClient: NodeOAuthClient): FastifyPluginCallback handle: session.handle, displayName: meUserRows[0]?.displayName ?? null, avatarUrl: meUserRows[0]?.avatarUrl ?? null, + role: meUserRows[0]?.role ?? 'user', crossPostScopesGranted: mePrefRows[0]?.crossPostScopesGranted ?? false, }) } catch (err: unknown) { -- 2.51.2