widget chat 23

This commit is contained in:
Alma 2025-04-11 12:41:19 +02:00
parent fb36b0334a
commit 48d65028f1

View File

@ -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;
}