widget email 12
This commit is contained in:
parent
5babc300b0
commit
a66a56f64d
@ -6,7 +6,7 @@ export async function GET(req: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
if (!session?.user?.email) {
|
if (!session?.user?.email || !session?.accessToken) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
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`, {
|
const response = await fetch(`${nextcloudUrl}/ocs/v2.php/apps/mail/api/v1/accounts`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'OCS-APIRequest': 'true',
|
'OCS-APIRequest': 'true',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
|
'Authorization': `Bearer ${session.accessToken}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const responseText = await response.text();
|
||||||
let responseData;
|
let responseData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
responseData = await response.json();
|
responseData = JSON.parse(responseText);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const text = await response.text();
|
console.error('Failed to parse response:', responseText);
|
||||||
console.error('Failed to parse response:', text);
|
|
||||||
return NextResponse.json({ error: 'Invalid response format' }, { status: 500 });
|
return NextResponse.json({ error: 'Invalid response format' }, { status: 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user