Skip to content

Commit

Permalink
Fix role admin not being detected (#269)
Browse files Browse the repository at this point in the history
* Console error when role is missing

* Fix admin login

* Remove error logs
  • Loading branch information
mauriciabad authored Jun 9, 2024
1 parent 7fe0064 commit 0ac723a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit 0ac723a

Please sign in to comment.