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