- Wire admin approval UI to editorialService.approveEditorial so editorial accounts can move pending_approval -> active and log in. The approve button was permanently disabled and the service unreachable, so editorial users could never sign in. - Surface non-validation errors (e.g. SMTP failures) on the registration form instead of silently redirecting to the confirmation page. - Set BETTER_AUTH_URL default to the production domain in .env.example and compose.yaml so verification/reset links and the login origin check resolve against the live origin. - Add scripts/check-smtp.ts to verify SMTP connectivity against the configured transport. Co-Authored-By: Claude <noreply@anthropic.com>
279 lines
8.1 KiB
TypeScript
279 lines
8.1 KiB
TypeScript
"use client";
|
|
|
|
import { type FormEvent, useActionState, useState } from "react";
|
|
|
|
import { authClient } from "./client";
|
|
|
|
export type RegistrationFormState = {
|
|
errors?: Partial<
|
|
Record<
|
|
| "form"
|
|
| "companyName"
|
|
| "contactName"
|
|
| "email"
|
|
| "password"
|
|
| "addressLine1"
|
|
| "postalCode"
|
|
| "city"
|
|
| "countryCode"
|
|
| "actsForBusiness"
|
|
| "termsVersion"
|
|
| "privacyAcknowledged",
|
|
string
|
|
>
|
|
>;
|
|
};
|
|
|
|
export type RegistrationFormAction = (
|
|
state: RegistrationFormState,
|
|
formData: FormData,
|
|
) => Promise<RegistrationFormState>;
|
|
|
|
export type LegalUrls = {
|
|
imprint: string;
|
|
privacy: string;
|
|
terms: string;
|
|
};
|
|
|
|
const initialRegistrationState: RegistrationFormState = {};
|
|
|
|
export function RegistrationForm({
|
|
action,
|
|
legalUrls,
|
|
}: {
|
|
action: RegistrationFormAction;
|
|
legalUrls: LegalUrls;
|
|
}) {
|
|
const [state, formAction, pending] = useActionState(action, initialRegistrationState);
|
|
|
|
return (
|
|
<form action={formAction} className="account-form">
|
|
<FieldError message={state.errors?.form} />
|
|
<div className="form-grid">
|
|
<label>
|
|
Redaktion oder Unternehmen
|
|
<input autoComplete="organization" name="companyName" required />
|
|
</label>
|
|
<FieldError message={state.errors?.companyName} />
|
|
<label>
|
|
Ansprechpartner:in
|
|
<input autoComplete="name" name="contactName" required />
|
|
</label>
|
|
<FieldError message={state.errors?.contactName} />
|
|
<label>
|
|
E-Mail-Adresse
|
|
<input autoComplete="email" name="email" required type="email" />
|
|
</label>
|
|
<FieldError message={state.errors?.email} />
|
|
<label>
|
|
Passwort
|
|
<input autoComplete="new-password" minLength={8} name="password" required type="password" />
|
|
</label>
|
|
<FieldError message={state.errors?.password} />
|
|
<label>
|
|
Straße und Hausnummer
|
|
<input autoComplete="address-line1" name="addressLine1" required />
|
|
</label>
|
|
<FieldError message={state.errors?.addressLine1} />
|
|
<label>
|
|
Adresszusatz
|
|
<input autoComplete="address-line2" name="addressLine2" />
|
|
</label>
|
|
<label>
|
|
Postleitzahl
|
|
<input autoComplete="postal-code" name="postalCode" required />
|
|
</label>
|
|
<FieldError message={state.errors?.postalCode} />
|
|
<label>
|
|
Ort
|
|
<input autoComplete="address-level2" name="city" required />
|
|
</label>
|
|
<FieldError message={state.errors?.city} />
|
|
<label>
|
|
Land (ISO-Code)
|
|
<input
|
|
autoComplete="country"
|
|
defaultValue="DE"
|
|
maxLength={2}
|
|
name="countryCode"
|
|
required
|
|
/>
|
|
</label>
|
|
<FieldError message={state.errors?.countryCode} />
|
|
</div>
|
|
|
|
<fieldset className="acknowledgements">
|
|
<legend>Verbindliche Angaben</legend>
|
|
<label className="checkbox-label">
|
|
<input name="actsForBusiness" required type="checkbox" />
|
|
Ich handle im Namen einer Redaktion oder eines Unternehmens.
|
|
</label>
|
|
<FieldError message={state.errors?.actsForBusiness} />
|
|
<label className="checkbox-label">
|
|
<input name="termsAccepted" required type="checkbox" />
|
|
Ich akzeptiere die{" "}
|
|
<a href={legalUrls.terms} rel="noreferrer" target="_blank">
|
|
Nutzungs- und Lizenzbedingungen
|
|
</a>
|
|
.
|
|
</label>
|
|
<FieldError message={state.errors?.termsVersion} />
|
|
<label className="checkbox-label">
|
|
<input name="privacyAcknowledged" required type="checkbox" />
|
|
Ich habe die{" "}
|
|
<a href={legalUrls.privacy} rel="noreferrer" target="_blank">
|
|
Datenschutzerklärung
|
|
</a>{" "}
|
|
zur Kenntnis genommen.
|
|
</label>
|
|
<FieldError message={state.errors?.privacyAcknowledged} />
|
|
</fieldset>
|
|
|
|
<button className="primary-action" disabled={pending} type="submit">
|
|
{pending ? "Registrierung wird gesendet …" : "Registrierung senden"}
|
|
</button>
|
|
<p className="form-note">
|
|
Wir informieren Sie auf der nächsten Seite über den weiteren Ablauf.
|
|
</p>
|
|
<a className="legal-link" href={legalUrls.imprint} rel="noreferrer" target="_blank">
|
|
Impressum
|
|
</a>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function LoginForm() {
|
|
const [error, setError] = useState<string>();
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
setPending(true);
|
|
setError(undefined);
|
|
|
|
const formData = new FormData(event.currentTarget);
|
|
const result = await authClient.signIn.email({
|
|
email: readText(formData, "email").trim().toLowerCase(),
|
|
password: readText(formData, "password"),
|
|
callbackURL: "/",
|
|
});
|
|
|
|
if (result.error) {
|
|
setError("Die Anmeldung war nicht erfolgreich. Bitte prüfen Sie Ihre Angaben.");
|
|
setPending(false);
|
|
return;
|
|
}
|
|
|
|
window.location.assign(result.data?.url ?? "/");
|
|
}
|
|
|
|
return (
|
|
<form className="account-form" onSubmit={submit}>
|
|
<label>
|
|
E-Mail-Adresse
|
|
<input autoComplete="email" name="email" required type="email" />
|
|
</label>
|
|
<label>
|
|
Passwort
|
|
<input autoComplete="current-password" name="password" required type="password" />
|
|
</label>
|
|
<FieldError message={error} />
|
|
<button className="primary-action" disabled={pending} type="submit">
|
|
{pending ? "Anmeldung wird geprüft …" : "Anmelden"}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function PasswordResetRequestForm() {
|
|
const [submitted, setSubmitted] = useState(false);
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
setPending(true);
|
|
const formData = new FormData(event.currentTarget);
|
|
|
|
try {
|
|
await authClient.requestPasswordReset({
|
|
email: readText(formData, "email").trim().toLowerCase(),
|
|
redirectTo: `${window.location.origin}/passwort-zuruecksetzen`,
|
|
});
|
|
} finally {
|
|
setSubmitted(true);
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
if (submitted) {
|
|
return (
|
|
<p className="form-note" role="status">
|
|
Falls ein Zugang zu dieser Adresse gehört, erhalten Sie in Kürze weitere Hinweise.
|
|
</p>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<form className="account-form" onSubmit={submit}>
|
|
<label>
|
|
E-Mail-Adresse
|
|
<input autoComplete="email" name="email" required type="email" />
|
|
</label>
|
|
<button className="primary-action" disabled={pending} type="submit">
|
|
{pending ? "Anfrage wird gesendet …" : "Link anfordern"}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function PasswordResetForm({ token }: { token?: string }) {
|
|
const [message, setMessage] = useState<string>();
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function submit(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
setPending(true);
|
|
const formData = new FormData(event.currentTarget);
|
|
|
|
try {
|
|
await authClient.resetPassword({ newPassword: readText(formData, "password"), token });
|
|
} finally {
|
|
setMessage("Wenn der Link gültig war, wurde Ihr Passwort aktualisiert.");
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
if (message) {
|
|
return (
|
|
<p className="form-note" role="status">
|
|
{message}
|
|
</p>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<form className="account-form" onSubmit={submit}>
|
|
<label>
|
|
Neues Passwort
|
|
<input autoComplete="new-password" minLength={8} name="password" required type="password" />
|
|
</label>
|
|
<button className="primary-action" disabled={pending} type="submit">
|
|
{pending ? "Passwort wird aktualisiert …" : "Passwort aktualisieren"}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function FieldError({ message }: { message?: string }) {
|
|
return message ? (
|
|
<p className="field-error" role="alert">
|
|
{message}
|
|
</p>
|
|
) : null;
|
|
}
|
|
|
|
function readText(formData: FormData, name: string): string {
|
|
const value = formData.get(name);
|
|
return typeof value === "string" ? value : "";
|
|
}
|