Fix next/headers import and add debug info for requireAuth

This commit is contained in:
Carlos (Almeira) 2026-07-01 19:54:04 -05:00
parent 970ebe4581
commit b0fdf220bc

View File

@ -9,6 +9,7 @@
* 4. Returns standardized ApiResponse<T>
*/
import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers';
import { ID, Query } from 'node-appwrite';
import { createSessionClient, createAdminClient } from '@/lib/appwrite.server';
import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite';
@ -34,7 +35,6 @@ async function requireAuth() {
try {
// Si es modo bypass (admin-emergency), no podemos llamar a account.get() con la API Key
const { cookies } = require('next/headers');
const cookieStore = await cookies();
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
const sessionCookie = cookieStore.get(`a_session_${PROJECT_ID.toLowerCase()}`);
@ -54,9 +54,9 @@ async function requireAuth() {
const user = await session.account.get();
return { user, session, error: null };
} catch {
} catch (error: any) {
return { user: null, error: NextResponse.json<ApiResponse>(
{ success: false, error: 'Sesión inválida o expirada.' },
{ success: false, error: 'Sesión inválida o expirada. Debug: ' + (error?.message || error) },
{ status: 401 }
)};
}