From e2da8cfca48981c01ee939b4dd2ef64351fcd8d4 Mon Sep 17 00:00:00 2001 From: Alma Date: Fri, 11 Apr 2025 12:44:33 +0200 Subject: [PATCH] widget chat 24 --- app/api/auth/[...nextauth]/route.ts | 6 ++++++ types/next-auth.d.ts | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 9eb3738e..d4329461 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -85,6 +85,12 @@ export const authOptions: NextAuthOptions = { // Initial sign in if (account && profile) { + // Set user data from profile + token.username = profile.preferred_username; + token.first_name = profile.given_name; + token.last_name = profile.family_name; + token.role = profile.groups || []; + // Get user info from Rocket.Chat using the admin token const userInfoResponse = await fetch(`${process.env.ROCKET_CHAT_URL}/api/v1/users.info?username=${token.username}`, { headers: { diff --git a/types/next-auth.d.ts b/types/next-auth.d.ts index e1a757bc..b634b9e7 100644 --- a/types/next-auth.d.ts +++ b/types/next-auth.d.ts @@ -40,10 +40,14 @@ declare module "next-auth" { } interface Profile { - given_name: string; - family_name: string; - preferred_username: string; - realm_roles: string[]; + sub: string; + email_verified: boolean; + name?: string | null; + preferred_username?: string | null; + given_name?: string | null; + family_name?: string | null; + email?: string | null; + groups?: string[]; } }