From 0ac723a4f76a371daf2d3e016b2e07a78ede4b5a Mon Sep 17 00:00:00 2001 From: Maurici Abad Gutierrez Date: Sun, 9 Jun 2024 17:15:06 +0200 Subject: [PATCH] Fix role admin not being detected (#269) * Console error when role is missing * Fix admin login * Remove error logs --- src/server/auth.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/server/auth.ts b/src/server/auth.ts index 3bebc141..85673784 100644 --- a/src/server/auth.ts +++ b/src/server/auth.ts @@ -66,7 +66,16 @@ export const authOptions: AuthOptions = { return { ...token, ...validatedSession } } if (trigger === 'signIn' || trigger === 'signUp') { - return { ...token, id: user.id, role: user.role } + const role = + user.role ?? + ( + await db.query.users.findFirst({ + where: eq(users.id, user.id), + columns: { role: true }, + }) + )?.role + + return { ...token, id: user.id, role } } return token },