Skip to content

fix(auth-next): keep the cookie when a fetch's refresh fails - #5

Merged
Wilsoon7721 merged 1 commit into
mainfrom
fix/keep-cookie-on-fetch-refresh-failure
Oct 10, 2026
Merged

Wilsoon7721 merged 1 commit into
mainfrom
fix/keep-cookie-on-fetch-refresh-failure

Conversation

@Wilsoon7721

@Wilsoon7721 Wilsoon7721 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4.

When a refresh fails on a spent token, createAuthMiddleware now only signs out on a navigation. A fetch gets the same redirect to loginPath, but its response no longer expires the cookie, since a request beside it may be writing freshly rotated tokens to that cookie at the same moment. The next navigation retries with whatever the cookie holds by then, and clears it if that refresh fails too.

  • packages/auth-next/src/middleware.ts: the catch around refreshAccessToken picks signOut() or a plain redirect by isNavigation.
  • Tests: the existing "refresh rejected" test now covers the navigation case and checks the cookie is expired; a new one checks a fetch is turned away with the cookie untouched.
  • Released as 3.0.1 for the three kit packages, with a changelog entry and a line in the auth-next README.

@Wilsoon7721
Wilsoon7721 merged commit 69bc822 into main Oct 10, 2026
1 check passed
@Wilsoon7721
Wilsoon7721 deleted the fix/keep-cookie-on-fetch-refresh-failure branch October 10, 2026 19:46
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.

Failed refresh on a background fetch deletes the cookie a parallel request just renewed

1 participant