carnet api
This commit is contained in:
parent
20ae56ce49
commit
9b6eed1b37
@ -2,14 +2,12 @@ import { NextResponse } from 'next/server';
|
|||||||
import { getServerSession } from 'next-auth';
|
import { getServerSession } from 'next-auth';
|
||||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
||||||
import { DOMParser } from '@xmldom/xmldom';
|
import { DOMParser } from '@xmldom/xmldom';
|
||||||
import { cookies } from 'next/headers';
|
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
const cookieStore = cookies();
|
|
||||||
|
|
||||||
if (!session?.user?.email) {
|
if (!session?.user?.email || !session?.accessToken) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: 'Unauthorized' },
|
{ error: 'Unauthorized' },
|
||||||
{ status: 401 }
|
{ status: 401 }
|
||||||
@ -36,35 +34,16 @@ export async function GET() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get user's folders using WebDAV with session cookies
|
// Get user's folders using WebDAV with Keycloak token
|
||||||
const webdavUrl = `${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(session.user.email)}/`;
|
const webdavUrl = `${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(session.user.email)}/`;
|
||||||
console.log('Requesting WebDAV URL:', webdavUrl);
|
console.log('Requesting WebDAV URL:', webdavUrl);
|
||||||
|
|
||||||
// Get all cookies from the request
|
|
||||||
const allCookies = cookieStore.getAll();
|
|
||||||
console.log('Available cookies:', allCookies.map(c => ({
|
|
||||||
name: c.name,
|
|
||||||
value: c.value.substring(0, 10) + '...', // Log partial value for security
|
|
||||||
domain: c.domain,
|
|
||||||
path: c.path,
|
|
||||||
secure: c.secure,
|
|
||||||
httpOnly: c.httpOnly,
|
|
||||||
sameSite: c.sameSite
|
|
||||||
})));
|
|
||||||
|
|
||||||
const cookieHeader = allCookies
|
|
||||||
.map(cookie => `${cookie.name}=${cookie.value}`)
|
|
||||||
.join('; ');
|
|
||||||
|
|
||||||
console.log('Sending cookie header:', cookieHeader.substring(0, 100) + '...'); // Log partial header
|
|
||||||
|
|
||||||
const foldersResponse = await fetch(webdavUrl, {
|
const foldersResponse = await fetch(webdavUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
'Cookie': cookieHeader,
|
'Authorization': `Bearer ${session.accessToken}`,
|
||||||
'Depth': '1',
|
'Depth': '1',
|
||||||
'Content-Type': 'application/xml',
|
'Content-Type': 'application/xml',
|
||||||
},
|
},
|
||||||
credentials: 'include', // Important for cookie handling
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!foldersResponse.ok) {
|
if (!foldersResponse.ok) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user