Fix: Back button after login causes "State not valid" error when user is already authenticated#1644
Draft
Fix: Back button after login causes "State not valid" error when user is already authenticated#1644
Conversation
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://black-rock-0dc6b0d03-1644.westeurope.1.azurestaticapps.net |
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://icy-glacier-004ab4303-1644.westeurope.2.azurestaticapps.net |
…ted (back button after login) Co-authored-by: guillaume-chervet <52236059+guillaume-chervet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix back button error after login state invalid
Fix: Back button after login causes "State not valid" error when user is already authenticated
Feb 24, 2026
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.
When an IdP like Keycloak silently re-authenticates on browser back navigation, it redirects to the callback URL with a fresh state. Since the original state was already consumed after first login, the stored state is
null, triggeringState not valid (expected: null, received: XXXXX)and showing the error page.Changes
packages/oidc-client/src/login.ts—loginCallbackAsyncserviceWorker.initAsync()(was previously discarded) to retrieve existing tokens from the service workersession.initAsync()to check for existing session tokensoidc.tokensor stored tokens are present (user is already authenticated), log a warning and return early with existing tokens + storedcallbackPathinstead of throwingpackages/oidc-client/src/login.spec.ts— new test file covering:oidc.tokensset → graceful redirectOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.