139 lines
4.6 KiB
TypeScript

"use client"
import React from "react"
import { useState } from "react"
import { useRouter } from "next/navigation"
import Link from "next/link"
import { createClient } from "@/lib/supabase/client"
import { Film, UserPlus, Loader2 } from "lucide-react"
export default function SignUpPage() {
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [displayName, setDisplayName] = useState("")
const [error, setError] = useState<string | null>(null)
const [loading, setLoading] = useState(false)
const router = useRouter()
async function handleSignUp(e: React.FormEvent) {
e.preventDefault()
setLoading(true)
setError(null)
const supabase = createClient()
const { error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo:
process.env.NEXT_PUBLIC_DEV_SUPABASE_REDIRECT_URL ||
`${window.location.origin}/feed`,
data: {
display_name: displayName,
},
},
})
if (error) {
setError(error.message)
setLoading(false)
return
}
router.push("/auth/sign-up-success")
}
return (
<main className="flex min-h-dvh flex-col items-center justify-center px-6">
<div className="w-full max-w-sm">
<div className="mb-10 flex flex-col items-center gap-3">
<div className="flex h-14 w-14 items-center justify-center rounded-2xl bg-primary">
<Film className="h-7 w-7 text-primary-foreground" />
</div>
<h1 className="font-heading text-3xl font-bold tracking-tight text-foreground">
Konto erstellen
</h1>
<p className="text-sm text-muted-foreground">
Tritt deinem Familien-Filmclub bei
</p>
</div>
<form onSubmit={handleSignUp} className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<label htmlFor="displayName" className="text-sm font-medium text-foreground">
Anzeigename
</label>
<input
id="displayName"
type="text"
value={displayName}
onChange={(e) => setDisplayName(e.target.value)}
placeholder="z.B. Papa, Mama, Lisa..."
required
className="h-12 rounded-lg border border-border bg-secondary px-4 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
/>
</div>
<div className="flex flex-col gap-2">
<label htmlFor="email" className="text-sm font-medium text-foreground">
E-Mail
</label>
<input
id="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="familie@example.com"
required
className="h-12 rounded-lg border border-border bg-secondary px-4 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
/>
</div>
<div className="flex flex-col gap-2">
<label htmlFor="password" className="text-sm font-medium text-foreground">
Passwort
</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Mindestens 6 Zeichen"
required
minLength={6}
className="h-12 rounded-lg border border-border bg-secondary px-4 text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"
/>
</div>
{error && (
<p className="text-sm text-destructive">{error}</p>
)}
<button
type="submit"
disabled={loading}
className="mt-2 flex h-12 items-center justify-center gap-2 rounded-lg bg-primary font-semibold text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50"
>
{loading ? (
<Loader2 className="h-5 w-5 animate-spin" />
) : (
<>
<UserPlus className="h-5 w-5" />
Registrieren
</>
)}
</button>
</form>
<p className="mt-6 text-center text-sm text-muted-foreground">
Bereits ein Konto?{" "}
<Link href="/auth/login" className="font-medium text-primary hover:underline">
Anmelden
</Link>
</p>
</div>
</main>
)
}