feat(auth): specific German login error messages by Better Auth code
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e50c7c2fd
commit
7cb168e846
1 file changed
+24
-1
@@ -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 ? (
|
||||
<p className="field-error" role="alert">
|
||||
|
||||
Reference in new issue
Block a user