115 lines
3.7 KiB
TypeScript
115 lines
3.7 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, Eye, Loader2 } from "lucide-react"
|
|
|
|
export default function LoginPage() {
|
|
const [email, setEmail] = useState("")
|
|
const [password, setPassword] = useState("")
|
|
const [error, setError] = useState<string | null>(null)
|
|
const [loading, setLoading] = useState(false)
|
|
const router = useRouter()
|
|
|
|
async function handleLogin(e: React.FormEvent) {
|
|
e.preventDefault()
|
|
setLoading(true)
|
|
setError(null)
|
|
|
|
const supabase = createClient()
|
|
const { error } = await supabase.auth.signInWithPassword({
|
|
email,
|
|
password,
|
|
})
|
|
|
|
if (error) {
|
|
setError("E-Mail oder Passwort falsch.")
|
|
setLoading(false)
|
|
return
|
|
}
|
|
|
|
router.push("/feed")
|
|
router.refresh()
|
|
}
|
|
|
|
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">
|
|
InFocus
|
|
</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
Familienfilm-Tagebuch
|
|
</p>
|
|
</div>
|
|
|
|
<form onSubmit={handleLogin} className="flex flex-col gap-4">
|
|
<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="Passwort eingeben"
|
|
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>
|
|
|
|
{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" />
|
|
) : (
|
|
<>
|
|
<Eye className="h-5 w-5" />
|
|
Anmelden
|
|
</>
|
|
)}
|
|
</button>
|
|
</form>
|
|
|
|
<p className="mt-6 text-center text-sm text-muted-foreground">
|
|
Noch kein Konto?{" "}
|
|
<Link href="/auth/sign-up" className="font-medium text-primary hover:underline">
|
|
Registrieren
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|