widget chat 10
This commit is contained in:
parent
f42ea1a8a6
commit
c66fb1d698
@ -139,13 +139,35 @@ export const authOptions: NextAuthOptions = {
|
|||||||
let personalToken: string | null = null;
|
let personalToken: string | null = null;
|
||||||
let rocketChatUserId: string | null = null;
|
let rocketChatUserId: string | null = null;
|
||||||
|
|
||||||
|
// First, get the user's Rocket.Chat ID
|
||||||
|
const userInfoResponse = await fetch(`https://parole.slm-lab.net/api/v1/users.info?username=${newToken.username}`, {
|
||||||
|
headers: {
|
||||||
|
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
||||||
|
'X-User-Id': process.env.ROCKET_CHAT_USER_ID!,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!userInfoResponse.ok) {
|
||||||
|
console.error('Failed to get user info from Rocket.Chat');
|
||||||
|
return newToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userInfo = await userInfoResponse.json();
|
||||||
|
console.log('User info from Rocket.Chat:', userInfo);
|
||||||
|
|
||||||
|
if (userInfo.user && userInfo.user._id) {
|
||||||
|
rocketChatUserId = userInfo.user._id;
|
||||||
|
} else {
|
||||||
|
console.error('No user ID found in Rocket.Chat response');
|
||||||
|
return newToken;
|
||||||
|
}
|
||||||
|
|
||||||
if (tokensData.tokens && tokensData.tokens.length > 0) {
|
if (tokensData.tokens && tokensData.tokens.length > 0) {
|
||||||
// Use existing token
|
// Use existing token
|
||||||
const existingToken = tokensData.tokens.find((t: any) => t.name === tokenName);
|
const existingToken = tokensData.tokens.find((t: any) => t.name === tokenName);
|
||||||
if (existingToken) {
|
if (existingToken) {
|
||||||
console.log('Found existing token:', existingToken);
|
console.log('Found existing token:', existingToken);
|
||||||
personalToken = existingToken.lastTokenPart;
|
personalToken = existingToken.lastTokenPart;
|
||||||
rocketChatUserId = process.env.ROCKET_CHAT_USER_ID!;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +191,6 @@ export const authOptions: NextAuthOptions = {
|
|||||||
const createTokenData = await createTokenResponse.json();
|
const createTokenData = await createTokenResponse.json();
|
||||||
console.log('Created token data:', createTokenData);
|
console.log('Created token data:', createTokenData);
|
||||||
personalToken = createTokenData.token;
|
personalToken = createTokenData.token;
|
||||||
rocketChatUserId = process.env.ROCKET_CHAT_USER_ID!;
|
|
||||||
} else {
|
} else {
|
||||||
console.error('Failed to create personal access token');
|
console.error('Failed to create personal access token');
|
||||||
return newToken;
|
return newToken;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user