Skip to content

Commit

Permalink
Console error when role is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciabad committed May 19, 2024
1 parent 7fe0064 commit 0eda07f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/server/helpers/auth/auth-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ export const adminAuthMiddleware = (
withAuth(middleware, {
callbacks: {
authorized: ({ token }) => {
return token?.role === 'admin'
if (!token) {
console.error('adminAuthMiddleware: User has no token')
return false
}

if (!token.role) {
console.error(
`adminAuthMiddleware: User "${token.id}" (${token.email}) has no role`
)
return false
}

return token.role === 'admin'
},
},
pages: {
Expand Down

0 comments on commit 0eda07f

Please sign in to comment.