widget chat 7
This commit is contained in:
parent
20caa97d71
commit
c00abc83af
@ -153,7 +153,7 @@ export const authOptions: NextAuthOptions = {
|
||||
if (existingToken) {
|
||||
console.log('Found existing token:', existingToken);
|
||||
personalToken = existingToken.lastTokenPart;
|
||||
rocketChatUserId = tokensData.userId;
|
||||
rocketChatUserId = process.env.ROCKET_CHAT_USER_ID!; // Use admin user ID for now
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ export const authOptions: NextAuthOptions = {
|
||||
const createTokenData = await createTokenResponse.json();
|
||||
console.log('Created token data:', createTokenData);
|
||||
personalToken = createTokenData.token;
|
||||
rocketChatUserId = createTokenData.userId;
|
||||
rocketChatUserId = process.env.ROCKET_CHAT_USER_ID!; // Use admin user ID for now
|
||||
} else {
|
||||
console.error('Failed to create personal access token');
|
||||
return token;
|
||||
@ -191,15 +191,23 @@ export const authOptions: NextAuthOptions = {
|
||||
}
|
||||
|
||||
if (personalToken && rocketChatUserId) {
|
||||
console.log('Setting Rocket.Chat credentials in token');
|
||||
token.rocketChatToken = personalToken;
|
||||
token.rocketChatUserId = rocketChatUserId;
|
||||
console.log('Setting Rocket.Chat credentials in token:', {
|
||||
tokenLength: personalToken.length,
|
||||
userId: rocketChatUserId
|
||||
});
|
||||
return {
|
||||
...token,
|
||||
rocketChatToken: personalToken,
|
||||
rocketChatUserId: rocketChatUserId,
|
||||
};
|
||||
} else {
|
||||
console.error('Failed to get Rocket.Chat credentials');
|
||||
return token;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error in Rocket.Chat authentication:', error);
|
||||
return token;
|
||||
}
|
||||
|
||||
return token;
|
||||
@ -248,18 +256,29 @@ export const authOptions: NextAuthOptions = {
|
||||
throw new Error("RefreshAccessTokenError");
|
||||
}
|
||||
|
||||
session.accessToken = token.accessToken;
|
||||
session.rocketChatToken = token.rocketChatToken;
|
||||
session.rocketChatUserId = token.rocketChatUserId;
|
||||
session.user = {
|
||||
...session.user,
|
||||
id: token.sub as string,
|
||||
first_name: token.first_name ?? '',
|
||||
last_name: token.last_name ?? '',
|
||||
username: token.username ?? '',
|
||||
role: token.role ?? [],
|
||||
// Ensure all required fields are present
|
||||
if (!token.rocketChatToken || !token.rocketChatUserId) {
|
||||
console.error('Missing Rocket.Chat credentials in token:', {
|
||||
hasToken: !!token.rocketChatToken,
|
||||
hasUserId: !!token.rocketChatUserId,
|
||||
token: token
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...session,
|
||||
accessToken: token.accessToken,
|
||||
rocketChatToken: token.rocketChatToken || '',
|
||||
rocketChatUserId: token.rocketChatUserId || '',
|
||||
user: {
|
||||
...session.user,
|
||||
id: token.sub as string,
|
||||
first_name: token.first_name || '',
|
||||
last_name: token.last_name || '',
|
||||
username: token.username || '',
|
||||
role: token.role || [],
|
||||
},
|
||||
};
|
||||
return session;
|
||||
},
|
||||
},
|
||||
events: {
|
||||
|
||||
@ -6,15 +6,27 @@ export async function GET() {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) {
|
||||
console.error('No session found');
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
console.log('Session data:', {
|
||||
hasToken: !!session.rocketChatToken,
|
||||
hasUserId: !!session.rocketChatUserId,
|
||||
tokenLength: session.rocketChatToken?.length,
|
||||
userIdLength: session.rocketChatUserId?.length
|
||||
});
|
||||
|
||||
// Get the user's Rocket.Chat token from their session
|
||||
const rocketChatToken = session.rocketChatToken;
|
||||
const rocketChatUserId = session.rocketChatUserId;
|
||||
|
||||
if (!rocketChatToken || !rocketChatUserId) {
|
||||
console.error('Missing Rocket.Chat credentials in user session');
|
||||
console.error('Missing Rocket.Chat credentials in session:', {
|
||||
hasToken: !!rocketChatToken,
|
||||
hasUserId: !!rocketChatUserId,
|
||||
session: session
|
||||
});
|
||||
return NextResponse.json({ error: "User not authenticated with Rocket.Chat" }, { status: 401 });
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user