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