DEBUG: Add auth debugging logs to identify file preview auth issue

This commit is contained in:
Matt 2025-06-15 16:53:20 +02:00
parent 4b3f75d4cf
commit 6c1a1fa842
1 changed files with 13 additions and 0 deletions

View File

@ -29,9 +29,22 @@ export const isAuthenticated = async (event: any): Promise<boolean> => {
export const requireAuth = async (event: any) => {
const authenticated = await isAuthenticated(event);
if (!authenticated) {
console.log('[requireAuth] Authentication failed for:', event.node.req.url);
console.log('[requireAuth] Available headers:', Object.keys(event.node.req.headers));
console.log('[requireAuth] Available cookies:', Object.keys(event.node.req.headers.cookie ? parseCookies(event.node.req.headers.cookie) : {}));
throw createError({
statusCode: 401,
statusMessage: "Authentication required. Please provide x-tag header or valid session."
});
}
}
function parseCookies(cookieString: string): Record<string, string> {
return cookieString.split(';').reduce((cookies: Record<string, string>, cookie) => {
const [name, value] = cookie.trim().split('=');
if (name && value) {
cookies[name] = value;
}
return cookies;
}, {});
}