update widget token 5 mail
This commit is contained in:
parent
01256ae58b
commit
20bddf3fca
@ -9,9 +9,13 @@ export async function GET() {
|
|||||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the user's info from Rocket.Chat using their username
|
if (!session.user?.email) {
|
||||||
|
return NextResponse.json({ error: "No email found in session" }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the user's info from Rocket.Chat using their email
|
||||||
const userInfoResponse = await fetch(
|
const userInfoResponse = await fetch(
|
||||||
`https://parole.slm-lab.net/api/v1/users.info?username=${session.user.username}`,
|
`https://parole.slm-lab.net/api/v1/users.info?email=${encodeURIComponent(session.user.email)}`,
|
||||||
{
|
{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
@ -26,7 +30,7 @@ export async function GET() {
|
|||||||
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,
|
email: session.user.email,
|
||||||
});
|
});
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: "Failed to fetch user info" },
|
{ error: "Failed to fetch user info" },
|
||||||
@ -38,13 +42,16 @@ export async function GET() {
|
|||||||
const userId = userInfo.user._id;
|
const userId = userInfo.user._id;
|
||||||
|
|
||||||
// Get the user's subscriptions (rooms they are in)
|
// Get the user's subscriptions (rooms they are in)
|
||||||
const subscriptionsResponse = await fetch('https://parole.slm-lab.net/api/v1/subscriptions.get', {
|
const subscriptionsResponse = await fetch(
|
||||||
|
`https://parole.slm-lab.net/api/v1/subscriptions.get?userId=${userId}`,
|
||||||
|
{
|
||||||
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 (!subscriptionsResponse.ok) {
|
if (!subscriptionsResponse.ok) {
|
||||||
console.error('Rocket.Chat subscriptions error:', {
|
console.error('Rocket.Chat subscriptions error:', {
|
||||||
@ -80,7 +87,11 @@ export async function GET() {
|
|||||||
|
|
||||||
if (messageResponse.ok) {
|
if (messageResponse.ok) {
|
||||||
const messageData = await messageResponse.json();
|
const messageData = await messageResponse.json();
|
||||||
return messageData.message;
|
return {
|
||||||
|
...messageData.message,
|
||||||
|
roomName: room.name || 'Direct Message',
|
||||||
|
roomType: room.t,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user