From 7cb168e846867a08a9360c4cd56ebbed6d3db5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 11 Aug 2026 01:28:29 +0200 Subject: [PATCH] feat(auth): specific German login error messages by Better Auth code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LoginForm mapped every signIn failure to one generic sentence. Better Auth returns distinct codes in signIn order — password check, then requireEmailVerification (EMAIL_NOT_VERIFIED), then the session.create.before hook canCreateSession (FAILED_TO_CREATE_SESSION). Map those to specific messages: unverified email, not-yet-approved account, invalid credentials. canCreateSession returns true only for ADMIN or editorial status 'active', and onEmailVerified → markPendingApproval leaves verified editorials at pending_approval until an admin approves — so the not-approved message is the common post-verification login block. Co-Authored-By: Claude --- src/modules/auth/public-forms.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 ? (