diff --git a/app/api/rocket-chat/messages/route.ts b/app/api/rocket-chat/messages/route.ts index 24440eed..66401311 100644 --- a/app/api/rocket-chat/messages/route.ts +++ b/app/api/rocket-chat/messages/route.ts @@ -9,13 +9,19 @@ export async function GET() { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - if (!session.user?.email) { - return NextResponse.json({ error: "No email found in session" }, { status: 400 }); + // Debug log to see all session data + console.log('Session data:', { + user: session.user, + accessToken: session.accessToken ? 'present' : 'missing' + }); + + if (!session.user?.username) { + return NextResponse.json({ error: "No username found in session" }, { status: 400 }); } - // Get the user's info from Rocket.Chat using their email + // Get the user's info from Rocket.Chat using their username const userInfoResponse = await fetch( - `https://parole.slm-lab.net/api/v1/users.info?email=${encodeURIComponent(session.user.email)}`, + `https://parole.slm-lab.net/api/v1/users.info?username=${encodeURIComponent(session.user.username)}`, { method: 'GET', headers: { @@ -30,7 +36,8 @@ export async function GET() { console.error('Rocket.Chat user info error:', { status: userInfoResponse.status, statusText: userInfoResponse.statusText, - email: session.user.email, + username: session.user.username, + response: await userInfoResponse.text().catch(() => 'Could not get response text') }); return NextResponse.json( { error: "Failed to fetch user info" }, @@ -57,6 +64,7 @@ export async function GET() { console.error('Rocket.Chat subscriptions error:', { status: subscriptionsResponse.status, statusText: subscriptionsResponse.statusText, + response: await subscriptionsResponse.text().catch(() => 'Could not get response text') }); return NextResponse.json( { error: "Failed to fetch subscriptions" }, @@ -93,6 +101,12 @@ export async function GET() { roomType: room.t, }; } + console.error('Failed to fetch message:', { + roomId: room._id, + messageId: room.lastMessage._id, + status: messageResponse.status, + response: await messageResponse.text().catch(() => 'Could not get response text') + }); return null; }) );