update widget token mail 12

This commit is contained in:
Alma 2025-04-09 23:56:31 +02:00
parent bb3acefc1a
commit 24c6a65747

View File

@ -56,45 +56,13 @@ export async function GET() {
);
}
// First authenticate as admin to get an auth token
const adminLoginResponse = await fetch(
'https://parole.slm-lab.net/api/v1/login',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
user: process.env.ROCKET_CHAT_ADMIN_USERNAME,
password: process.env.ROCKET_CHAT_ADMIN_PASSWORD
})
}
);
if (!adminLoginResponse.ok) {
console.error('Rocket.Chat admin login error:', {
status: adminLoginResponse.status,
statusText: adminLoginResponse.statusText,
response: await adminLoginResponse.text().catch(() => 'Could not get response text')
});
return NextResponse.json(
{ error: "Failed to authenticate with Rocket.Chat" },
{ status: adminLoginResponse.status }
);
}
const adminAuth = await adminLoginResponse.json();
console.log('Admin auth success:', {
hasToken: !!adminAuth.data?.authToken
});
// Get user info by username using admin token
// Get user info using personal access token
const userInfoResponse = await fetch(
`https://parole.slm-lab.net/api/v1/users.info?username=${username}`,
{
headers: {
'X-Auth-Token': adminAuth.data.authToken,
'X-User-Id': adminAuth.data.userId
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
'X-User-Id': process.env.ROCKET_CHAT_USER_ID!
}
}
);
@ -122,7 +90,7 @@ export async function GET() {
'https://parole.slm-lab.net/api/v1/subscriptions.get',
{
headers: {
'X-Auth-Token': adminAuth.data.authToken,
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
'X-User-Id': userInfo.user._id
}
}
@ -154,7 +122,7 @@ export async function GET() {
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
{
headers: {
'X-Auth-Token': adminAuth.data.authToken,
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
'X-User-Id': userInfo.user._id
}
}