widget email 12

This commit is contained in:
Alma 2025-04-13 21:25:47 +02:00
parent 5babc300b0
commit a66a56f64d

View File

@ -6,7 +6,7 @@ export async function GET(req: NextRequest) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.email) {
if (!session?.user?.email || !session?.accessToken) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
@ -19,22 +19,24 @@ export async function GET(req: NextRequest) {
);
}
// Try to access the Mail app directly
// Try to access the Mail app using the Keycloak token
const response = await fetch(`${nextcloudUrl}/ocs/v2.php/apps/mail/api/v1/accounts`, {
headers: {
'Accept': 'application/json',
'OCS-APIRequest': 'true',
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'Authorization': `Bearer ${session.accessToken}`,
},
});
const responseText = await response.text();
let responseData;
try {
responseData = await response.json();
responseData = JSON.parse(responseText);
} catch (error) {
const text = await response.text();
console.error('Failed to parse response:', text);
console.error('Failed to parse response:', responseText);
return NextResponse.json({ error: 'Invalid response format' }, { status: 500 });
}