Skip to content

fix(web): show auth errors instead of silently reloading#242

Merged
vernu merged 1 commit into
devfrom
fix/auth-form-errors
Jul 19, 2026
Merged

fix(web): show auth errors instead of silently reloading#242
vernu merged 1 commit into
devfrom
fix/auth-form-errors

Conversation

@vernu

@vernu vernu commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the login form showing no message on wrong credentials and just reloading the page. While verifying the sign-up and forgot-password flows for the same issue, two related bugs on the password-reset form were found and fixed.

Changes

  • login-form: the submit handler called signIn(..., { redirect: true }), which makes next-auth navigate on both success and failure, so the browser reloaded and the error branch was never reached. Switched to redirect: false, so the result is read locally: the message renders on failure and a successful login navigates via router.push + router.refresh.
  • reset-password-form: two fixes.
    • The error was set under a nested root.serverError key while the JSX rendered errors.root.message, so a failed reset showed an empty paragraph. Aligned both to root, and errors are cleared at the start of each submit.
    • The catch swallowed the failure, leaving isSubmitSuccessful true, so the success alert rendered even on failure. The alert is now gated on the absence of a root error.
  • register-form: already correct (redirect: false); added a regression test so the login bug cannot reappear here unnoticed.

Tests

Component specs for all three forms (vitest + React Testing Library) with the Turnstile hook and the network boundary mocked. Each new failing case was confirmed to fail against the pre-change component before the fix; the login mock reflects real next-auth redirect semantics so the "shows an error" test is a faithful guard.

Verification

typecheck clean, build clean, 0 lint errors (warnings unchanged), unit tests 155 to 164.

🤖 Generated with Claude Code

Login showed no message on wrong credentials and just reloaded. The
handler called signIn with redirect:true, which makes next-auth navigate
on both success and failure, so the browser reloaded to /login?error=
and the `if (result?.error)` branch never ran: the error handling was
dead code. Switched to redirect:false, so the result is read here, the
message renders, and success navigates via router.push + refresh.

The password-reset (OTP) form had two related bugs, both found while
verifying the "check forgot-password too" ask:
- It set form error under `root.serverError` but the JSX rendered
  `errors.root.message`, which a nested key leaves undefined, so a failed
  reset showed an empty paragraph and no text.
- The catch swallowed the error, so react-hook-form's isSubmitSuccessful
  stayed true and the "Password reset successful" alert rendered even on
  failure. The success alert is now gated on the absence of a root error,
  and errors are cleared at the start of each submit.

register-form was already correct (redirect:false); added a regression
test so the login bug cannot reappear there unnoticed.

Tests: component specs for all three forms under vitest + RTL, with
useTurnstile and the network boundary mocked. Each new failing case was
confirmed to fail against the pre-change component before the fix. The
login signIn mock reflects real redirect semantics (redirect:true yields
no readable result), so the "shows an error" test is a faithful guard.

Verified: typecheck clean, build clean, 0 lint errors (20 warnings,
unchanged), 164 unit tests (from 155).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
textbee Ready Ready Preview, Comment Jul 19, 2026 5:25pm

Request Review

@vernu
vernu merged commit e46b832 into dev Jul 19, 2026
5 checks passed
@vernu
vernu deleted the fix/auth-form-errors branch July 19, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant