Skip to content

fix(auth): stop reload from redirecting logged-in users to /login - #474

Merged
zigzagdev merged 2 commits into
mainfrom
fix/auth-provider-reload-redirect
Jul 30, 2026
Merged

zigzagdev merged 2 commits into
mainfrom
fix/auth-provider-reload-redirect

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Jul 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Bug: reloading an auth-required page (e.g. /mypage) while logged in redirected to /login, even though the token was still valid in localStorage
  • Root cause: <StrictMode> double-invokes AuthProvider's effect in dev. The first invocation's getCurrentUser call gets aborted by React's Strict Mode cleanup, but AuthProvider didn't check for AbortError before calling setUser(null)/setLoading(false) — unlike every other hook in this codebase (useCreateUser, etc.), which all guard against acting on an aborted request's result. The aborted call's rejection resolved before the second (real) request finished, so RequireAuth briefly saw isLoading:false, user:null and navigated away before the real request could complete
  • Fix: guard AuthProvider's getCurrentUser .catch/.finally with the same isAbortError check used elsewhere

Test plan

  • npx tsc --noEmit
  • npx jest — added a regression test that reproduces the StrictMode double-effect race; confirmed it fails against the pre-fix code and passes with the fix
  • npm run format:check

@zigzagdev zigzagdev self-assigned this Jul 30, 2026

@zigzagdev zigzagdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zigzagdev
zigzagdev merged commit 7526222 into main Jul 30, 2026
1 check passed
@zigzagdev
zigzagdev deleted the fix/auth-provider-reload-redirect branch July 30, 2026 01:00
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.

fix: reloadで/mypage等の認証必須ページから/loginに誤ってリダイレクトされる

1 participant