import Link from "next/link";
import { redirect } from "next/navigation";
import { headers } from "next/headers";
import { env } from "@/config/env";
import { registerEditorial } from "@/modules/auth/auth";
import {
CURRENT_TERMS_VERSION,
RegistrationValidationError,
} from "@/modules/auth/registration";
import {
RegistrationForm,
type RegistrationFormState,
} from "@/modules/auth/public-forms";
import { RateLimitExceededError } from "@/modules/security/rate-limit-guard";
export default function RegistrationPage() {
return (
Leon Tonhäuser
Redaktionsportal
B2B-Zugang
Redaktion registrieren
Das Redaktionsportal steht ausschließlich Unternehmen und Redaktionen zur Verfügung.
);
}
async function registerAction(
_state: RegistrationFormState,
formData: FormData,
): Promise {
"use server";
try {
await registerEditorial({
companyName: text(formData, "companyName"),
contactName: text(formData, "contactName"),
email: text(formData, "email"),
password: text(formData, "password"),
billingAddress: {
addressLine1: text(formData, "addressLine1"),
addressLine2: text(formData, "addressLine2") || undefined,
postalCode: text(formData, "postalCode"),
city: text(formData, "city"),
countryCode: text(formData, "countryCode"),
},
actsForBusiness: formData.has("actsForBusiness"),
termsVersion: formData.has("termsAccepted") ? CURRENT_TERMS_VERSION : "",
privacyAcknowledged: formData.has("privacyAcknowledged"),
}, await headers());
} catch (error) {
if (error instanceof RateLimitExceededError) {
return {
errors: {
form: "Es wurden zu viele Registrierungsversuche gesendet. Bitte versuchen Sie es später erneut.",
},
};
}
if (error instanceof RegistrationValidationError) {
return { errors: { [error.field]: error.message } };
}
return {
errors: {
form: "Die Registrierung konnte nicht abgeschlossen werden. Bitte versuchen Sie es später erneut.",
},
};
}
redirect("/registrieren/bestaetigt");
}
function text(formData: FormData, name: string): string {
const value = formData.get(name);
return typeof value === "string" ? value : "";
}