widget parole 10
This commit is contained in:
parent
f9b7ef1891
commit
2697471b03
@ -66,29 +66,43 @@ export async function GET(request: Request) {
|
||||
return NextResponse.json({ messages: [] }, { status: 200 });
|
||||
}
|
||||
|
||||
let userInfo;
|
||||
// Try to get user info by username first
|
||||
const userInfoResponse = await fetch(`${baseUrl}/api/v1/users.info?username=${encodeURIComponent(username)}`, {
|
||||
method: 'GET',
|
||||
headers: adminHeaders
|
||||
});
|
||||
|
||||
if (!userInfoResponse.ok) {
|
||||
console.error('Failed to get user info:', userInfoResponse.status);
|
||||
console.error('Failed to get user info by username:', userInfoResponse.status);
|
||||
const errorData = await userInfoResponse.json();
|
||||
console.error('User info error details:', errorData);
|
||||
|
||||
// If user not found, return empty messages instead of error
|
||||
if (errorData.error === 'User not found.') {
|
||||
// Try to get user info by email as fallback
|
||||
const emailUserInfoResponse = await fetch(`${baseUrl}/api/v1/users.info?email=${encodeURIComponent(session.user.email)}`, {
|
||||
method: 'GET',
|
||||
headers: adminHeaders
|
||||
});
|
||||
|
||||
if (!emailUserInfoResponse.ok) {
|
||||
console.error('Failed to get user info by email:', emailUserInfoResponse.status);
|
||||
const emailErrorData = await emailUserInfoResponse.json();
|
||||
console.error('Email user info error details:', emailErrorData);
|
||||
return NextResponse.json({ messages: [] }, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: 'Failed to get user info' }, { status: userInfoResponse.status });
|
||||
}
|
||||
|
||||
const userInfo = await userInfoResponse.json();
|
||||
console.log('Found Rocket.Chat user:', {
|
||||
username: userInfo.user?.username,
|
||||
id: userInfo.user?._id
|
||||
});
|
||||
userInfo = await emailUserInfoResponse.json();
|
||||
console.log('Found Rocket.Chat user by email:', {
|
||||
username: userInfo.user?.username,
|
||||
id: userInfo.user?._id
|
||||
});
|
||||
} else {
|
||||
userInfo = await userInfoResponse.json();
|
||||
console.log('Found Rocket.Chat user by username:', {
|
||||
username: userInfo.user?.username,
|
||||
id: userInfo.user?._id
|
||||
});
|
||||
}
|
||||
|
||||
// Get user's subscriptions using admin token
|
||||
const subscriptionsResponse = await fetch(`${baseUrl}/api/v1/subscriptions.get`, {
|
||||
@ -132,7 +146,7 @@ export async function GET(request: Request) {
|
||||
try {
|
||||
// Get the latest messages from the room
|
||||
const messagesResponse = await fetch(
|
||||
`${baseUrl}/api/v1/chat.getMessage?roomId=${subscription.rid}`, {
|
||||
`${baseUrl}/api/v1/channels.messages?roomId=${subscription.rid}&count=1`, {
|
||||
method: 'GET',
|
||||
headers: adminHeaders
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user