From 48d65028f1cc98f533eda4d469f011549e2e614d Mon Sep 17 00:00:00 2001 From: Alma Date: Fri, 11 Apr 2025 12:41:19 +0200 Subject: [PATCH] widget chat 23 --- app/api/auth/[...nextauth]/route.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index d6a13b4e..9eb3738e 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -84,7 +84,7 @@ export const authOptions: NextAuthOptions = { console.log('JWT callback called with:', { token, account, profile }); // Initial sign in - if (account) { + if (account && profile) { // 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: { @@ -172,7 +172,12 @@ export const authOptions: NextAuthOptions = { return token; } - // Return previous token if not expired + // Return previous token if it has Rocket.Chat credentials + if (token.rocketChatToken && token.rocketChatUserId) { + return token; + } + + // Token refresh case if (Date.now() < (token.accessTokenExpires as number)) { return token; }