Nexo P1 fix — clearer login error when PocketBase rejects credentials

PocketBase returns HTTP 400 with `{ ok: false, error: { code: 400,
message: "Failed to authenticate." } }` when the email isn't found
or the password is wrong. The dating server passes the envelope
through verbatim, so the previous client showed "Failed to
authenticate." in English with no hint about what to do next.

Login now translates that pattern to "Email o contraseña incorrectos.
Si no tienes cuenta, regístrate primero." — the second clause is the
common case when a user mistakes the demo for an existing account
and tries to log in before registering.

Detection lives in the page (not in the API client) because it's a
UI-copy concern, not a contract issue: the server's structured
`error.code` is genuinely the upstream HTTP status here, and other
400 responses from this endpoint (e.g. `missing_field` on an empty
body) keep their own dedicated branches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
master
dev 5 months ago
parent 9399cc58a6
commit c6392c317f

@ -30,16 +30,28 @@
function messageFor(error: DatingApiError): string {
switch (error.code) {
case 'invalid_credentials':
return 'Email o contraseña incorrectos.';
return 'Email o contraseña incorrectos. Si no tienes cuenta, regístrate primero.';
case 'account_restricted':
return 'Tu cuenta está restringida. Contacta con soporte.';
case 'mfa_required':
return 'Esta cuenta requiere verificación adicional.';
case 'network_error':
return 'No se ha podido conectar con el servidor. Vuelve a intentarlo.';
default:
return error.message || 'Algo ha ido mal. Vuelve a intentarlo.';
case 'missing_field':
return 'Faltan campos obligatorios.';
}
// PocketBase rejects bad credentials with HTTP 400 and a numeric
// `code: 400`. The dating server passes the envelope through
// verbatim, so any 400 with a generic auth-failed message ends
// up here — translate it instead of leaking the upstream
// English text into the UI.
if (
error.status === 400 &&
(error.message === 'Failed to authenticate.' || String(error.code) === '400')
) {
return 'Email o contraseña incorrectos. Si no tienes cuenta, regístrate primero.';
}
return error.message || 'Algo ha ido mal. Vuelve a intentarlo.';
}
async function submit(event: SubmitEvent) {

Loading…
Cancel
Save

Powered by TurnKey Linux.