fix: contacts API - use ADMIN_JWT_SECRET env var
This commit is contained in:
parent
822ab076b4
commit
320b77b32b
@ -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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user