Phase 3: admin magic-link auth and event setup screens
- /login sends a Supabase magic link (admin emails only); /auth/confirm completes sign-in; proxy.ts guards /admin and every server action re-checks with requireAdmin(), since actions are plain POST endpoints. - /admin lists, creates, duplicates and deletes events. - /admin/events/[eventId] edits teams (colour, order) and games with criteria, presets and notes. All input goes through zod schemas that mirror the database constraints so errors read as plain sentences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
import type { Database } from "@/lib/database.types";
|
||||
import { publicEnv } from "@/lib/env.public";
|
||||
|
||||
/**
|
||||
* Refreshes the admin's auth cookie (Server Components can't write cookies, so the proxy
|
||||
* does it) and returns the verified JWT claims, or null when signed out.
|
||||
*/
|
||||
export async function updateSession(request: NextRequest) {
|
||||
let response = NextResponse.next({ request });
|
||||
|
||||
const supabase = createServerClient<Database>(
|
||||
publicEnv.NEXT_PUBLIC_SUPABASE_URL,
|
||||
publicEnv.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
||||
{
|
||||
cookies: {
|
||||
getAll() {
|
||||
return request.cookies.getAll();
|
||||
},
|
||||
setAll(cookiesToSet) {
|
||||
cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value));
|
||||
response = NextResponse.next({ request });
|
||||
cookiesToSet.forEach(({ name, value, options }) =>
|
||||
response.cookies.set(name, value, options),
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
// getClaims() verifies the token's signature; never trust the raw cookie.
|
||||
const { data } = await supabase.auth.getClaims();
|
||||
return { response, claims: data?.claims ?? null };
|
||||
}
|
||||
Reference in New Issue
Block a user