fix(admin): fresh SSR reads, atomic user delete + sanitized errors, cookie-rotation in middleware, no-store on admin APIs
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server';
|
||||
import { type NextRequest } from 'next/server';
|
||||
import { requireAdminApi } from '@/lib/auth/admin-guard';
|
||||
import { getSupabaseAdmin } from '@/lib/supabase/admin';
|
||||
import { logAdminAction } from '@/lib/auth/audit';
|
||||
import { isUuid, parsePositiveInt } from '@/lib/admin/validators';
|
||||
import { jsonNoStore } from '@/lib/admin/response';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -19,18 +20,18 @@ export async function POST(
|
||||
|
||||
const { id } = params;
|
||||
if (!isUuid(id)) {
|
||||
return NextResponse.json({ error: 'invalid tunnel id' }, { status: 400 });
|
||||
return jsonNoStore({ error: 'invalid tunnel id' }, { status: 400 });
|
||||
}
|
||||
|
||||
let body: { quota_bytes?: unknown };
|
||||
try {
|
||||
body = (await req.json()) as { quota_bytes?: unknown };
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'invalid json' }, { status: 400 });
|
||||
return jsonNoStore({ error: 'invalid json' }, { status: 400 });
|
||||
}
|
||||
const parsed = parsePositiveInt(body.quota_bytes, MAX_QUOTA);
|
||||
if (!parsed.ok) {
|
||||
return NextResponse.json(
|
||||
return jsonNoStore(
|
||||
{ error: `quota_bytes ${parsed.error}` },
|
||||
{ status: 400 },
|
||||
);
|
||||
@@ -44,10 +45,11 @@ export async function POST(
|
||||
.select('subdomain')
|
||||
.maybeSingle<{ subdomain: string }>();
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
console.error('admin tunnel.quota failed', error);
|
||||
return jsonNoStore({ error: 'internal error' }, { status: 500 });
|
||||
}
|
||||
if (!data) {
|
||||
return NextResponse.json({ error: 'tunnel not found' }, { status: 404 });
|
||||
return jsonNoStore({ error: 'tunnel not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await logAdminAction(auth.user, {
|
||||
@@ -57,5 +59,5 @@ export async function POST(
|
||||
details: { subdomain: data.subdomain, quota_bytes: parsed.value },
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, quota_bytes: parsed.value });
|
||||
return jsonNoStore({ ok: true, quota_bytes: parsed.value });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user