diff --git a/src/modules/auth/public-forms.tsx b/src/modules/auth/public-forms.tsx index 1f26ae3..6750634 100644 --- a/src/modules/auth/public-forms.tsx +++ b/src/modules/auth/public-forms.tsx @@ -159,7 +159,7 @@ export function LoginForm() { }); if (result.error) { - setError("Die Anmeldung war nicht erfolgreich. Bitte prüfen Sie Ihre Angaben."); + setError(loginErrorMessage(result.error.code)); setPending(false); return; } @@ -264,6 +264,29 @@ export function PasswordResetForm({ token }: { token?: string }) { ); } +// Maps Better Auth's signIn error codes to specific German messages. The +// signIn flow checks in order: password → email verification (requireEmailVerification) +// → session creation (databaseHooks.session.create.before → canCreateSession). +// canCreateSession returns true only for ADMIN or editorial status "active", so a +// verified-but-not-yet-approved editorial (status pending_approval after onEmailVerified +// → markPendingApproval) lands on FAILED_TO_CREATE_SESSION = "noch nicht freigeschaltet". +// ponytail: one message per real flow state; suspended/rejected share the approval +// message for now — refine with status-specific hook codes if that stops being enough. +function loginErrorMessage(code: string | undefined): string { + switch (code) { + case "EMAIL_NOT_VERIFIED": + return "Bitte bestätigen Sie Ihre E-Mail-Adresse über den Link in der E-Mail, die wir Ihnen gesendet haben."; + case "FAILED_TO_CREATE_SESSION": + return "Ihr Konto ist noch nicht freigeschaltet. Sobald ein Administrator Ihre Registrierung bestätigt hat, erhalten Sie Zugriff."; + case "INVALID_EMAIL_OR_PASSWORD": + case "INVALID_PASSWORD": + case "USER_NOT_FOUND": + return "Falsche E-Mail oder falsches Passwort."; + default: + return "Die Anmeldung ist fehlgeschlagen. Bitte versuchen Sie es später erneut."; + } +} + function FieldError({ message }: { message?: string }) { return message ? (