fix: surface bad-login error inline instead of silent page reload#558
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When auth is enabled, submitting wrong credentials on the login form gave the
user no feedback: the page silently reloaded and the only trace was a
401in theconsole.
Root cause. The global 401 interceptor in
apiFetch(web/lib/api.ts) redirectsto
/loginand returns a never-resolving promise on every 401. The login andregister requests go through
apiFetchtoo, so a 401 from wrong credentials triggereda full-page reload back to
/login, andlogin()never resolved —handleSubmitnever reached
setError, so no inline error was ever shown.Fix. Add an opt-out
skipAuthRedirectflag toapiFetchand pass it from thelogin()andregister()calls, so their401/400responses are returned to thecaller and rendered as inline form errors. The expired-session redirect still applies
to every other endpoint, unchanged.
Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservicestoolsutilsweb(Frontend)docs(Documentation)scriptstests...Checklist
pre-commitand fixed any issues.Additional Notes
Behavior
401in console, no messageAfter:
Tests —
web/tests/api-auth-redirect.test.ts(run withnpm run test:node):apiFetchredirects to/loginon 401 by default.apiFetchdoes not redirect on 401 whenskipAuthRedirectis set, and returnsthe 401 +
detailto the caller — the regression guard for this bug.Verification
tscclean; node test suite 3/3 pass.!skipAuthRedirectguard makes the regression testfail as expected, confirming the test actually catches the regression.
pre-commit run --files <changed files>— all applicable hooks pass.POST /api/v1/auth/loginwith bad credentialsreturns
401 {"detail":"Incorrect username or password"}— the text now renderedinline (see screenshot).