update widget token mail 6
This commit is contained in:
parent
f68a0a873d
commit
daa8de03a4
@ -15,41 +15,35 @@ export async function GET() {
|
||||
accessToken: session.accessToken ? 'present' : 'missing'
|
||||
});
|
||||
|
||||
// First, login to Rocket.Chat using OAuth
|
||||
const loginResponse = await fetch('https://parole.slm-lab.net/api/v1/login', {
|
||||
method: 'POST',
|
||||
// First, get user info using the OAuth token
|
||||
const meResponse = await fetch('https://parole.slm-lab.net/api/v1/me', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
'Authorization': `Bearer ${session.accessToken}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
serviceName: 'keycloak',
|
||||
accessToken: session.accessToken,
|
||||
expiresIn: 200
|
||||
})
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
if (!loginResponse.ok) {
|
||||
console.error('Rocket.Chat login error:', {
|
||||
status: loginResponse.status,
|
||||
statusText: loginResponse.statusText,
|
||||
response: await loginResponse.text().catch(() => 'Could not get response text')
|
||||
if (!meResponse.ok) {
|
||||
console.error('Rocket.Chat me error:', {
|
||||
status: meResponse.status,
|
||||
statusText: meResponse.statusText,
|
||||
response: await meResponse.text().catch(() => 'Could not get response text')
|
||||
});
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to authenticate with Rocket.Chat" },
|
||||
{ status: loginResponse.status }
|
||||
{ error: "Failed to get user info from Rocket.Chat" },
|
||||
{ status: meResponse.status }
|
||||
);
|
||||
}
|
||||
|
||||
const loginData = await loginResponse.json();
|
||||
const { authToken, userId } = loginData.data;
|
||||
const userData = await meResponse.json();
|
||||
const { _id: userId } = userData;
|
||||
|
||||
// Get the user's subscriptions (rooms they are in)
|
||||
const subscriptionsResponse = await fetch(
|
||||
'https://parole.slm-lab.net/api/v1/subscriptions.get',
|
||||
{
|
||||
headers: {
|
||||
'X-Auth-Token': authToken,
|
||||
'X-User-Id': userId,
|
||||
'Authorization': `Bearer ${session.accessToken}`
|
||||
},
|
||||
cache: 'no-store',
|
||||
}
|
||||
@ -81,8 +75,7 @@ export async function GET() {
|
||||
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
|
||||
{
|
||||
headers: {
|
||||
'X-Auth-Token': authToken,
|
||||
'X-User-Id': userId,
|
||||
'Authorization': `Bearer ${session.accessToken}`
|
||||
},
|
||||
cache: 'no-store',
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user