From 24c6a6574770d007fb7609c519231e56278c7d1b Mon Sep 17 00:00:00 2001 From: Alma Date: Wed, 9 Apr 2025 23:56:31 +0200 Subject: [PATCH] update widget token mail 12 --- app/api/rocket-chat/messages/route.ts | 42 ++++----------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/app/api/rocket-chat/messages/route.ts b/app/api/rocket-chat/messages/route.ts index b8d87bd1..c07c172b 100644 --- a/app/api/rocket-chat/messages/route.ts +++ b/app/api/rocket-chat/messages/route.ts @@ -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 } }