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,37 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState } from "react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, inputClass } from "@/components/ui/field";
|
||||
|
||||
import { sendMagicLink, type LoginState } from "./actions";
|
||||
|
||||
const initialState: LoginState = { status: "idle", message: "" };
|
||||
|
||||
export function LoginForm({ initialError }: { initialError: string | null }) {
|
||||
const [state, formAction, pending] = useActionState(sendMagicLink, initialState);
|
||||
const error = state.status === "error" ? state.message : state.status === "idle" ? initialError : null;
|
||||
|
||||
return (
|
||||
<form action={formAction} className="flex flex-col gap-4">
|
||||
<Field label="Email">
|
||||
<input
|
||||
name="email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
required
|
||||
className={inputClass}
|
||||
placeholder="you@example.com"
|
||||
/>
|
||||
</Field>
|
||||
<Button type="submit" disabled={pending}>
|
||||
{pending ? "Sending…" : "Send sign-in link"}
|
||||
</Button>
|
||||
<p role="status" aria-live="polite" className="min-h-6">
|
||||
{state.status === "sent" && <span className="font-bold text-ink">{state.message}</span>}
|
||||
{error && <span className="font-bold text-alert">{error}</span>}
|
||||
</p>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user