feat: add editorial registration and authentication
This commit is contained in:
1 parent
7acaacb92e
commit
9b22752ef2
20 files changed
+1728
-20
No files matched your search
@@ -0,0 +1,75 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { env } from "@/config/env";
|
||||
import { registerEditorial } from "@/modules/auth/auth";
|
||||
import { RegistrationValidationError } from "@/modules/auth/registration";
|
||||
import {
|
||||
RegistrationForm,
|
||||
type RegistrationFormState,
|
||||
} from "@/modules/auth/public-forms";
|
||||
|
||||
export default function RegistrationPage() {
|
||||
return (
|
||||
<main className="public-account-page">
|
||||
<header className="masthead">
|
||||
<Link className="wordmark" href="/">
|
||||
Leon Tonhäuser
|
||||
</Link>
|
||||
<span className="section-label">Redaktionsportal</span>
|
||||
</header>
|
||||
<section className="account-panel account-panel-wide" aria-labelledby="registration-title">
|
||||
<p className="eyebrow">B2B-Zugang</p>
|
||||
<h1 id="registration-title">Redaktion registrieren</h1>
|
||||
<p className="lede">
|
||||
Das Redaktionsportal steht ausschließlich Unternehmen und Redaktionen zur Verfügung.
|
||||
</p>
|
||||
<RegistrationForm
|
||||
action={registerAction}
|
||||
legalUrls={{
|
||||
imprint: env.LEGAL_IMPRINT_URL,
|
||||
privacy: env.LEGAL_PRIVACY_URL,
|
||||
terms: env.LEGAL_TERMS_URL,
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
async function registerAction(
|
||||
_state: RegistrationFormState,
|
||||
formData: FormData,
|
||||
): Promise<RegistrationFormState> {
|
||||
"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") ? text(formData, "termsVersion") : "",
|
||||
privacyAcknowledged: formData.has("privacyAcknowledged"),
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof RegistrationValidationError) {
|
||||
return { errors: { [error.field]: error.message } };
|
||||
}
|
||||
}
|
||||
|
||||
redirect("/registrieren/bestaetigt");
|
||||
}
|
||||
|
||||
function text(formData: FormData, name: string): string {
|
||||
const value = formData.get(name);
|
||||
return typeof value === "string" ? value : "";
|
||||
}
|
||||
Reference in new issue
Block a user