121 lines
3.7 KiB
TypeScript
121 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"
|
|
import { useLanguage } from "@/contexts/LanguageContext"
|
|
import { LanguageToggle } from "@/components/language-toggle"
|
|
|
|
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()
|
|
const { t } = useLanguage()
|
|
|
|
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(t("auth.invalidCredentials"))
|
|
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-6 flex justify-end">
|
|
<LanguageToggle />
|
|
</div>
|
|
<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">
|
|
{t("auth.familyMovieDiary")}
|
|
</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">
|
|
{t("auth.email")}
|
|
</label>
|
|
<input
|
|
id="email"
|
|
type="email"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="familie@example.com"
|
|
required
|
|
className="glass-input h-12 text-sm"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<label htmlFor="password" className="text-sm font-medium text-foreground">
|
|
{t("auth.password")}
|
|
</label>
|
|
<input
|
|
id="password"
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder={t("auth.passwordPlaceholder")}
|
|
required
|
|
className="glass-input h-12 text-sm"
|
|
/>
|
|
</div>
|
|
|
|
{error && (
|
|
<p className="text-sm text-destructive">{error}</p>
|
|
)}
|
|
|
|
<button
|
|
type="submit"
|
|
disabled={loading}
|
|
className="glass-button mt-2 flex h-12 items-center justify-center gap-2 bg-primary font-semibold text-primary-foreground shadow-lg shadow-primary/20 disabled:opacity-50"
|
|
>
|
|
{loading ? (
|
|
<Loader2 className="h-5 w-5 animate-spin" />
|
|
) : (
|
|
<>
|
|
<Eye className="h-5 w-5" />
|
|
{t("auth.signIn")}
|
|
</>
|
|
)}
|
|
</button>
|
|
</form>
|
|
|
|
<p className="mt-6 text-center text-sm text-muted-foreground">
|
|
{t("auth.dontHaveAccount")}{" "}
|
|
<Link href="/auth/sign-up" className="font-medium text-primary hover:underline">
|
|
{t("auth.signUp")}
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|