update widget token 2
This commit is contained in:
parent
f25c9ba83d
commit
8e8894c819
@ -9,13 +9,36 @@ export async function GET() {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
// Use the personal access token to authenticate with Rocket.Chat
|
||||
const response = await fetch('https://parole.slm-lab.net/api/v1/channels.messages', {
|
||||
// First, get the user's info from Rocket.Chat using their email
|
||||
const userInfoResponse = await fetch('https://parole.slm-lab.net/api/v1/users.info', {
|
||||
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,
|
||||
});
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch user info" },
|
||||
{ status: userInfoResponse.status }
|
||||
);
|
||||
}
|
||||
|
||||
const userInfo = await userInfoResponse.json();
|
||||
const userId = userInfo.user._id;
|
||||
|
||||
// Get the last messages for the user
|
||||
const response = await fetch(`https://parole.slm-lab.net/api/v1/im.messages?userId=${userId}&count=50`, {
|
||||
headers: {
|
||||
'X-Auth-Token': 'C_3ekrsgtsaU0sVQzpJ8aRSyMQjBIvcsmXVvBI8Wmgb',
|
||||
'X-User-Id': 'Tpuww59PJKsrGNQJB',
|
||||
},
|
||||
// Add cache control to prevent stale data
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user