Aktueller Stand
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { signIn } from "next-auth/react";
|
||||
import { getSession, signIn } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [showVerifyLink, setShowVerifyLink] = useState(false);
|
||||
const [registrationEnabled, setRegistrationEnabled] = useState<boolean | null>(
|
||||
null
|
||||
);
|
||||
const [registered, setRegistered] = useState(false);
|
||||
const [prefillEmail, setPrefillEmail] = useState("");
|
||||
const [emailVerificationRequired, setEmailVerificationRequired] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined") return;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
setRegistered(params.get("registered") === "1");
|
||||
setPrefillEmail(params.get("email") || "");
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const loadRegistration = async () => {
|
||||
@@ -20,8 +28,10 @@ export default function LoginPage() {
|
||||
if (!response.ok) return;
|
||||
const payload = await response.json();
|
||||
setRegistrationEnabled(payload.registrationEnabled !== false);
|
||||
setEmailVerificationRequired(payload.emailVerificationRequired !== false);
|
||||
} catch {
|
||||
setRegistrationEnabled(true);
|
||||
setEmailVerificationRequired(true);
|
||||
}
|
||||
};
|
||||
loadRegistration();
|
||||
@@ -38,9 +48,15 @@ export default function LoginPage() {
|
||||
const result = await signIn("credentials", {
|
||||
email,
|
||||
password,
|
||||
redirect: false
|
||||
redirect: false,
|
||||
callbackUrl: "/"
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
setError("Login fehlgeschlagen.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (result?.error) {
|
||||
if (result.error === "PENDING") {
|
||||
setError("Dein Konto wartet auf Freischaltung durch einen Admin.");
|
||||
@@ -65,7 +81,12 @@ export default function LoginPage() {
|
||||
|
||||
if (result?.ok) {
|
||||
setShowVerifyLink(false);
|
||||
router.push("/");
|
||||
const session = await getSession();
|
||||
if (!session?.user) {
|
||||
setError("Login fehlgeschlagen.");
|
||||
return;
|
||||
}
|
||||
window.location.href = result.url || "/";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,12 +96,20 @@ export default function LoginPage() {
|
||||
<p className="mt-1 text-sm text-slate-600">
|
||||
Bitte anmelden.
|
||||
</p>
|
||||
{registered && (
|
||||
<div className="mt-4 rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-700">
|
||||
{emailVerificationRequired
|
||||
? "Account erstellt. Bitte E-Mail bestätigen und auf die Freischaltung durch einen Admin warten."
|
||||
: "Account erstellt. Bitte auf die Freischaltung durch einen Admin warten."}
|
||||
</div>
|
||||
)}
|
||||
<form onSubmit={onSubmit} className="mt-4 space-y-3">
|
||||
<input
|
||||
name="email"
|
||||
type="email"
|
||||
placeholder="E-Mail"
|
||||
required
|
||||
defaultValue={prefillEmail}
|
||||
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
||||
/>
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user