"use client"; import Link from "next/link"; import { signIn } from "next-auth/react"; import { useEffect, useState } from "react"; export default function RegisterPage() { const [error, setError] = useState(null); const [done, setDone] = useState(false); const [registrationEnabled, setRegistrationEnabled] = useState( null ); useEffect(() => { const loadRegistration = async () => { try { const response = await fetch("/api/settings/registration"); if (!response.ok) return; const payload = await response.json(); setRegistrationEnabled(payload.registrationEnabled !== false); } catch { setRegistrationEnabled(true); } }; loadRegistration(); }, []); const onSubmit = async (event: React.FormEvent) => { event.preventDefault(); setError(null); const formData = new FormData(event.currentTarget); const payload = { name: formData.get("name"), email: formData.get("email"), password: formData.get("password") }; const response = await fetch("/api/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); if (!response.ok) { const data = await response.json(); setError(data.error || "Registrierung fehlgeschlagen."); return; } setDone(true); await signIn("credentials", { email: payload.email, password: payload.password, callbackUrl: "/" }); }; return (

Registrieren

{registrationEnabled === false ? (
Registrierung ist derzeit deaktiviert.
) : registrationEnabled === null ? (

Registrierung wird geladen...

) : ( <>
{done && (

Account erstellt.

)} {error &&

{error}

} )}

Schon registriert? Login

); }