widget parole 6
This commit is contained in:
parent
ed34ef30eb
commit
656a37d568
@ -65,18 +65,27 @@ export async function GET(request: Request) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// First, get the user's Rocket.Chat ID using their email
|
// 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',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
...adminHeaders,
|
...adminHeaders,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
}
|
||||||
// Add email as query parameter
|
|
||||||
query: `?username=${session.user.email?.split('@')[0]}`
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!userInfoResponse.ok) {
|
if (!userInfoResponse.ok) {
|
||||||
console.error('Failed to get user info:', userInfoResponse.status);
|
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' }), {
|
return new Response(JSON.stringify({ error: 'Failed to get user info' }), {
|
||||||
status: userInfoResponse.status,
|
status: userInfoResponse.status,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@ -132,10 +141,9 @@ export async function GET(request: Request) {
|
|||||||
try {
|
try {
|
||||||
// Get the latest messages from the room
|
// Get the latest messages from the room
|
||||||
const messagesResponse = await fetch(
|
const messagesResponse = await fetch(
|
||||||
`${baseUrl}/api/v1/channels.messages`, {
|
`${baseUrl}/api/v1/channels.messages?roomId=${subscription.rid}&count=1`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: adminHeaders,
|
headers: adminHeaders
|
||||||
query: `?roomId=${subscription.rid}&count=1`
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!messagesResponse.ok) {
|
if (!messagesResponse.ok) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user