widget parole 6

This commit is contained in:
Alma 2025-04-13 00:22:14 +02:00
parent ed34ef30eb
commit 656a37d568

View File

@ -65,18 +65,27 @@ export async function GET(request: Request) {
};
// First, get the user's Rocket.Chat ID using their email
const userInfoResponse = await fetch(`${baseUrl}/api/v1/users.info`, {
const username = session.user.email?.split('@')[0];
if (!username) {
console.error('No username found in session email');
return new Response(JSON.stringify({ error: 'No username found' }), {
status: 400,
headers: { 'Content-Type': 'application/json' },
});
}
const userInfoResponse = await fetch(`${baseUrl}/api/v1/users.info?username=${encodeURIComponent(username)}`, {
method: 'GET',
headers: {
...adminHeaders,
'Content-Type': 'application/json'
},
// Add email as query parameter
query: `?username=${session.user.email?.split('@')[0]}`
}
});
if (!userInfoResponse.ok) {
console.error('Failed to get user info:', userInfoResponse.status);
const errorData = await userInfoResponse.json();
console.error('User info error details:', errorData);
return new Response(JSON.stringify({ error: 'Failed to get user info' }), {
status: userInfoResponse.status,
headers: { 'Content-Type': 'application/json' },
@ -132,10 +141,9 @@ export async function GET(request: Request) {
try {
// Get the latest messages from the room
const messagesResponse = await fetch(
`${baseUrl}/api/v1/channels.messages`, {
`${baseUrl}/api/v1/channels.messages?roomId=${subscription.rid}&count=1`, {
method: 'GET',
headers: adminHeaders,
query: `?roomId=${subscription.rid}&count=1`
headers: adminHeaders
});
if (!messagesResponse.ok) {