update widget token mail 7
This commit is contained in:
parent
daa8de03a4
commit
4ac8ee20eb
@ -15,10 +15,17 @@ export async function GET() {
|
|||||||
accessToken: session.accessToken ? 'present' : 'missing'
|
accessToken: session.accessToken ? 'present' : 'missing'
|
||||||
});
|
});
|
||||||
|
|
||||||
// First, get user info using the OAuth token
|
if (!session.accessToken) {
|
||||||
|
return NextResponse.json({ error: "No access token found" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, get user info using the OAuth token with additional headers
|
||||||
const meResponse = await fetch('https://parole.slm-lab.net/api/v1/me', {
|
const meResponse = await fetch('https://parole.slm-lab.net/api/v1/me', {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${session.accessToken}`
|
'Authorization': `Bearer ${session.accessToken}`,
|
||||||
|
'X-Auth-Token': session.accessToken,
|
||||||
|
'X-User-Id': session.user.id,
|
||||||
|
'X-Oauth-User': session.user.username || session.user.email?.split('@')[0] || '',
|
||||||
},
|
},
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
@ -27,6 +34,10 @@ export async function GET() {
|
|||||||
console.error('Rocket.Chat me error:', {
|
console.error('Rocket.Chat me error:', {
|
||||||
status: meResponse.status,
|
status: meResponse.status,
|
||||||
statusText: meResponse.statusText,
|
statusText: meResponse.statusText,
|
||||||
|
headers: {
|
||||||
|
'X-Oauth-User': session.user.username || session.user.email?.split('@')[0] || '',
|
||||||
|
'Authorization': 'Bearer [hidden]'
|
||||||
|
},
|
||||||
response: await meResponse.text().catch(() => 'Could not get response text')
|
response: await meResponse.text().catch(() => 'Could not get response text')
|
||||||
});
|
});
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@ -36,14 +47,20 @@ export async function GET() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userData = await meResponse.json();
|
const userData = await meResponse.json();
|
||||||
const { _id: userId } = userData;
|
console.log('Rocket.Chat user data:', {
|
||||||
|
userId: userData._id,
|
||||||
|
username: userData.username
|
||||||
|
});
|
||||||
|
|
||||||
// Get the user's subscriptions (rooms they are in)
|
// Get the user's subscriptions (rooms they are in)
|
||||||
const subscriptionsResponse = await fetch(
|
const subscriptionsResponse = await fetch(
|
||||||
'https://parole.slm-lab.net/api/v1/subscriptions.get',
|
'https://parole.slm-lab.net/api/v1/subscriptions.get',
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${session.accessToken}`
|
'Authorization': `Bearer ${session.accessToken}`,
|
||||||
|
'X-Auth-Token': session.accessToken,
|
||||||
|
'X-User-Id': userData._id,
|
||||||
|
'X-Oauth-User': userData.username,
|
||||||
},
|
},
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
}
|
}
|
||||||
@ -75,7 +92,10 @@ export async function GET() {
|
|||||||
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
|
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${session.accessToken}`
|
'Authorization': `Bearer ${session.accessToken}`,
|
||||||
|
'X-Auth-Token': session.accessToken,
|
||||||
|
'X-User-Id': userData._id,
|
||||||
|
'X-Oauth-User': userData.username,
|
||||||
},
|
},
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user