Members register via email+password (scrypt) or Google OAuth — same signed-cookie + scrypt pattern as LokiLab (lib/auth.ts, member-password.ts, member-auth.ts, google-oauth.ts), own AUTH_SECRET and own OAuth client, own dedicated Postgres database (lokiloto-db on Coolify), fully isolated from LokiLab's own DB and auth. Leaderboard tracks who follows Loki's picks most accurately — members star a pick from the results panel (FollowButton), resolution reuses LokiLab's own lastDraw.won, no money or pooled play involved anywhere. Leaderboard page renders a horizontal bar chart (recharts) plus a ranked list. Profile page: public nickname (required to appear on the leaderboard), list of followed picks. Header now carries nav + a user menu (avatar dropdown when signed in, "Connexion" button otherwise). Dockerfile runs prisma migrate deploy at container start via docker-entrypoint.sh, same pattern as LokiLab. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
"use client"
|
|
|
|
import { useActionState, useState } from "react"
|
|
import { loginWithPassword, signupWithPassword, type MemberAuthState } from "@/app/connexion/actions"
|
|
import { Button } from "@/components/ui/button"
|
|
import { Input } from "@/components/ui/input"
|
|
import { Label } from "@/components/ui/label"
|
|
import { cn } from "@/lib/utils"
|
|
|
|
const INITIAL: MemberAuthState = { ok: false, message: "" }
|
|
|
|
export function MemberAuthForm({ next }: { next: string }) {
|
|
const [mode, setMode] = useState<"login" | "signup">("login")
|
|
const [loginState, loginAction, loginPending] = useActionState(loginWithPassword, INITIAL)
|
|
const [signupState, signupActionFn, signupPending] = useActionState(signupWithPassword, INITIAL)
|
|
|
|
const action = mode === "login" ? loginAction : signupActionFn
|
|
const state = mode === "login" ? loginState : signupState
|
|
const pending = mode === "login" ? loginPending : signupPending
|
|
|
|
return (
|
|
<div>
|
|
<div className="mb-4 flex rounded-md border border-border/60 bg-panel p-1 text-sm">
|
|
<button
|
|
type="button"
|
|
onClick={() => setMode("login")}
|
|
className={cn(
|
|
"flex-1 rounded py-1.5 font-medium transition-colors",
|
|
mode === "login" ? "bg-panel-hover text-foreground" : "text-muted-foreground"
|
|
)}
|
|
>
|
|
Connexion
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setMode("signup")}
|
|
className={cn(
|
|
"flex-1 rounded py-1.5 font-medium transition-colors",
|
|
mode === "signup" ? "bg-panel-hover text-foreground" : "text-muted-foreground"
|
|
)}
|
|
>
|
|
Créer un compte
|
|
</button>
|
|
</div>
|
|
|
|
<form action={action} className="space-y-3">
|
|
<input type="hidden" name="next" value={next} />
|
|
{mode === "signup" && (
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="name">Nom</Label>
|
|
<Input id="name" name="name" type="text" required autoComplete="name" />
|
|
</div>
|
|
)}
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="email">Courriel</Label>
|
|
<Input id="email" name="email" type="email" required autoComplete="email" />
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="password">Mot de passe</Label>
|
|
<Input
|
|
id="password"
|
|
name="password"
|
|
type="password"
|
|
required
|
|
minLength={mode === "signup" ? 8 : undefined}
|
|
autoComplete={mode === "login" ? "current-password" : "new-password"}
|
|
/>
|
|
{mode === "signup" && (
|
|
<p className="text-[11px] text-muted-foreground">8 caractères minimum.</p>
|
|
)}
|
|
</div>
|
|
|
|
{!state.ok && state.message && <p className="text-xs text-destructive">{state.message}</p>}
|
|
|
|
<Button type="submit" disabled={pending} className="w-full">
|
|
{pending ? "…" : mode === "login" ? "Se connecter" : "Créer mon compte"}
|
|
</Button>
|
|
</form>
|
|
</div>
|
|
)
|
|
}
|