From 3b35c2e71a8e67b7b0aa8956b3592f0c64dba9b4 Mon Sep 17 00:00:00 2001 From: alma Date: Fri, 18 Apr 2025 15:01:32 +0200 Subject: [PATCH] session correction sidebar items 8 --- app/api/auth/[...nextauth]/route.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 0e021bd7..39c7c5ef 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -144,7 +144,7 @@ export const authOptions: NextAuthOptions = { console.log('JWT raw roles:', roles); // Clean up roles by removing ROLE_ prefix and converting to lowercase - const cleanRoles = roles.map(role => + const cleanRoles = roles.map((role: string) => role.replace(/^ROLE_/, '').toLowerCase() ); @@ -158,6 +158,11 @@ export const authOptions: NextAuthOptions = { token.username = keycloakProfile.preferred_username ?? ''; token.first_name = keycloakProfile.given_name ?? ''; token.last_name = keycloakProfile.family_name ?? ''; + + console.log('JWT callback final token:', { + tokenRoles: token.role, + token + }); } if (Date.now() < (token.accessTokenExpires as number) * 1000) {