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,9 +1,10 @@
|
||||
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, parseBoolean } from '@/lib/admin/validators';
|
||||
import { redisSet } from '@/lib/redis';
|
||||
import { jsonNoStore } from '@/lib/admin/response';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
@@ -17,18 +18,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: { is_active?: unknown };
|
||||
try {
|
||||
body = (await req.json()) as { is_active?: unknown };
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'invalid json' }, { status: 400 });
|
||||
return jsonNoStore({ error: 'invalid json' }, { status: 400 });
|
||||
}
|
||||
const isActive = parseBoolean(body.is_active);
|
||||
if (isActive === null) {
|
||||
return NextResponse.json(
|
||||
return jsonNoStore(
|
||||
{ error: 'is_active must be a boolean' },
|
||||
{ status: 400 },
|
||||
);
|
||||
@@ -42,10 +43,11 @@ export async function POST(
|
||||
.select('subdomain')
|
||||
.maybeSingle<{ subdomain: string }>();
|
||||
if (error) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
console.error('admin tunnel.active 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 });
|
||||
}
|
||||
|
||||
// Best-effort live kill-switch (never throws).
|
||||
@@ -58,5 +60,5 @@ export async function POST(
|
||||
details: { subdomain: data.subdomain, is_active: isActive },
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true, is_active: isActive });
|
||||
return jsonNoStore({ ok: true, is_active: isActive });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user