update widget token 4

This commit is contained in:
Alma 2025-04-09 23:04:41 +02:00
parent c18ff84673
commit 01256ae58b

View File

@ -9,20 +9,24 @@ export async function GET() {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// First, get the user's info from Rocket.Chat
const userInfoResponse = await fetch('https://parole.slm-lab.net/api/v1/users.info', {
// Get the user's info from Rocket.Chat using their username
const userInfoResponse = await fetch(
`https://parole.slm-lab.net/api/v1/users.info?username=${session.user.username}`,
{
method: 'GET',
headers: {
'X-Auth-Token': 'C_3ekrsgtsaU0sVQzpJ8aRSyMQjBIvcsmXVvBI8Wmgb',
'X-User-Id': 'Tpuww59PJKsrGNQJB',
},
cache: 'no-store',
});
}
);
if (!userInfoResponse.ok) {
console.error('Rocket.Chat user info error:', {
status: userInfoResponse.status,
statusText: userInfoResponse.statusText,
username: session.user.username,
});
return NextResponse.json(
{ error: "Failed to fetch user info" },
@ -61,8 +65,10 @@ export async function GET() {
// Get the last message from each room
const messages = await Promise.all(
subscriptions.update.map(async (room: any) => {
if (!room.lastMessage?._id) return null;
const messageResponse = await fetch(
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage?._id}`,
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
{
headers: {
'X-Auth-Token': 'C_3ekrsgtsaU0sVQzpJ8aRSyMQjBIvcsmXVvBI8Wmgb',