update widget token mail 12
This commit is contained in:
parent
bb3acefc1a
commit
24c6a65747
@ -56,45 +56,13 @@ export async function GET() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// First authenticate as admin to get an auth token
|
// Get user info using personal access 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
|
|
||||||
const userInfoResponse = await fetch(
|
const userInfoResponse = await fetch(
|
||||||
`https://parole.slm-lab.net/api/v1/users.info?username=${username}`,
|
`https://parole.slm-lab.net/api/v1/users.info?username=${username}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'X-Auth-Token': adminAuth.data.authToken,
|
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
||||||
'X-User-Id': adminAuth.data.userId
|
'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',
|
'https://parole.slm-lab.net/api/v1/subscriptions.get',
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'X-Auth-Token': adminAuth.data.authToken,
|
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
||||||
'X-User-Id': userInfo.user._id
|
'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}`,
|
`https://parole.slm-lab.net/api/v1/chat.getMessage?msgId=${room.lastMessage._id}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
'X-Auth-Token': adminAuth.data.authToken,
|
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
||||||
'X-User-Id': userInfo.user._id
|
'X-User-Id': userInfo.user._id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user