All checks were successful
Container-Image bauen und veröffentlichen / build-and-push (push) Successful in 5m15s
141 lines
4.8 KiB
TypeScript
141 lines
4.8 KiB
TypeScript
"use client"
|
|
|
|
import { useState } from "react"
|
|
import { getSession, signIn } from "next-auth/react"
|
|
import { useRouter } from "next/navigation"
|
|
import { AlertCircle, Eye, EyeOff, ShieldCheck } from "lucide-react"
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
import { Input } from "@/components/ui/input"
|
|
import { Label } from "@/components/ui/label"
|
|
import { ThemeToggle } from "@/components/theme-toggle"
|
|
import { useAppName } from "@/components/providers/app-config-provider"
|
|
|
|
export default function SignInPage() {
|
|
const appName = useAppName()
|
|
|
|
const [email, setEmail] = useState("")
|
|
const [password, setPassword] = useState("")
|
|
const [showPassword, setShowPassword] = useState(false)
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
const [error, setError] = useState("")
|
|
const router = useRouter()
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
setIsLoading(true)
|
|
setError("")
|
|
|
|
try {
|
|
const result = await signIn("credentials", {
|
|
email,
|
|
password,
|
|
redirect: false,
|
|
})
|
|
|
|
if (result?.error) {
|
|
setError("Ungültige Anmeldedaten")
|
|
} else {
|
|
const session = await getSession()
|
|
if (session) {
|
|
router.push("/admin")
|
|
router.refresh()
|
|
}
|
|
}
|
|
} catch {
|
|
setError("Ein Fehler ist aufgetreten")
|
|
} finally {
|
|
setIsLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex min-h-screen flex-col bg-background">
|
|
<div className="flex justify-end p-4">
|
|
<ThemeToggle />
|
|
</div>
|
|
|
|
<main id="inhalt" tabIndex={-1} className="flex flex-1 items-center justify-center px-4 pb-20 sm:px-6">
|
|
<div className="w-full max-w-sm space-y-6">
|
|
<div className="flex flex-col items-center gap-3 text-center">
|
|
<div className="flex size-11 items-center justify-center rounded-xl bg-brand text-brand-foreground">
|
|
<ShieldCheck className="size-6" />
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
<h1 className="text-xl leading-none font-semibold tracking-tight">
|
|
{appName}
|
|
</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
Anmeldung zum Admin-Portal
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
{error && (
|
|
<div id="signin-error" role="alert" className="flex items-center gap-2.5 rounded-lg border border-destructive/30 bg-destructive/5 p-3 text-sm text-destructive">
|
|
<AlertCircle className="size-4 shrink-0" />
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="email">E-Mail-Adresse</Label>
|
|
<Input
|
|
id="email"
|
|
type="email"
|
|
aria-invalid={!!error}
|
|
aria-describedby={error ? "signin-error" : undefined}
|
|
autoComplete="username"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="name@firma.de"
|
|
required
|
|
disabled={isLoading}
|
|
/>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<Label htmlFor="password">Passwort</Label>
|
|
<div className="relative">
|
|
<Input
|
|
id="password"
|
|
type={showPassword ? "text" : "password"}
|
|
aria-invalid={!!error}
|
|
aria-describedby={error ? "signin-error" : undefined}
|
|
autoComplete="current-password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="••••••••"
|
|
required
|
|
disabled={isLoading}
|
|
className="pr-10"
|
|
/>
|
|
<Button
|
|
type="button"
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
className="absolute top-1/2 right-0.5 -translate-y-1/2 text-muted-foreground"
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
disabled={isLoading}
|
|
>
|
|
{showPassword ? <EyeOff /> : <Eye />}
|
|
<span className="sr-only">{showPassword ? "Passwort verbergen" : "Passwort anzeigen"}</span>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<Button type="submit" className="w-full" disabled={isLoading}>
|
|
{isLoading ? "Anmeldung…" : "Anmelden"}
|
|
</Button>
|
|
</form>
|
|
|
|
<p className="text-center text-xs text-muted-foreground">
|
|
Zugang nur für berechtigte Administratoren
|
|
</p>
|
|
</div>
|
|
</main>
|
|
</div>
|
|
)
|
|
}
|