fix: contacts API - use ADMIN_JWT_SECRET env var
Some checks are pending
CI/CD / test-and-build (push) Waiting to run
CI/CD / deploy (push) Blocked by required conditions

This commit is contained in:
Najjar\NajjarV02 2026-04-20 14:31:21 +04:00
parent 822ab076b4
commit 320b77b32b

View File

@ -11,8 +11,12 @@ export async function GET(request: Request) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
const secret = new TextEncoder().encode(process.env.JWT_SECRET || 'fallback-secret'); const jwtSecret = process.env.ADMIN_JWT_SECRET;
await jose.jwtVerify(token, secret); if (!jwtSecret) {
console.error('[/api/admin/contacts] ADMIN_JWT_SECRET is not defined');
return NextResponse.json({ error: 'Server error', detail: 'Missing JWT_SECRET env var' }, { status: 500 });
}
await jose.jwtVerify(token, new TextEncoder().encode(jwtSecret));
const contacts = await prisma.contactRequest.findMany({ const contacts = await prisma.contactRequest.findMany({
orderBy: { createdAt: 'desc' }, orderBy: { createdAt: 'desc' },
@ -20,7 +24,8 @@ export async function GET(request: Request) {
return NextResponse.json({ contacts }); return NextResponse.json({ contacts });
} catch (error) { } catch (error) {
console.error('Failed to load contacts:', error); console.error('[/api/admin/contacts] Full error:', error);
return NextResponse.json({ error: 'Failed to load contacts' }, { status: 500 }); const message = error instanceof Error ? error.message : String(error);
return NextResponse.json({ error: 'Failed to load contacts', detail: message }, { status: 500 });
} }
} }