fix: keep the auto-login redirect route per browser tab - #2272
Open
RhisiartK wants to merge 3 commits into
Open
Conversation
…pecs keep real storage
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a multi-tab race in the auto-login guards by making the “pending redirect route” tab-local (using sessionStorage) instead of being stored in the configured/shared storage (e.g., localStorage), preventing concurrent logins in different tabs from overwriting each other’s redirect.
Changes:
- Store and retrieve the auto-login redirect route from
sessionStorage(keyed by<configId>-redirect), with fallback to configured storage for backward compatibility. - Add/extend unit tests covering tab-local behavior, legacy fallback/cleanup, and sessionStorage-unavailable fallback.
- Update docs to clarify that the preserved route is stored per browser tab; minor test hardening in
BrowserStorageServicespecs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| projects/angular-auth-oidc-client/src/lib/storage/browser-storage.service.spec.ts | Restores mutated global Storage in the hasStorage test (test hygiene). |
| projects/angular-auth-oidc-client/src/lib/auto-login/auto-login.service.ts | Implements tab-local redirect route storage via sessionStorage, with legacy fallback and cleanup. |
| projects/angular-auth-oidc-client/src/lib/auto-login/auto-login.service.spec.ts | Adds test coverage for per-tab redirect behavior, legacy fallback consumption, and missing sessionStorage fallback. |
| docs/site/angular-auth-oidc-client/docs/documentation/auto-login.md | Documents that preserved routes are stored per browser tab using sessionStorage. |
Suppressed comments (2)
projects/angular-auth-oidc-client/src/lib/auto-login/auto-login.service.ts:52
getStoredRedirectRoutealso builds a sessionStorage key fromconfig.configIdeven though it is optional, so a config withoutconfigIdwould read fromundefined-redirectinstead of matching the previous behavior (read from configured storage / return null).
const tabLocalRoute = this.document.defaultView?.sessionStorage?.getItem(
`${config.configId}-${STORAGE_KEY}`
);
projects/angular-auth-oidc-client/src/lib/auto-login/auto-login.service.ts:64
deleteStoredRedirectRouteremoves from sessionStorage usingconfig.configIdeven when it is missing, which would attempt to removeundefined-redirect(and could delete unrelated data if anything else uses that key). Guarding on a truthy configId keeps semantics aligned with the configured storage path.
this.document.defaultView?.sessionStorage?.removeItem(
`${config.configId}-${STORAGE_KEY}`
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+37
to
+43
| const tabLocalStorage = this.document.defaultView?.sessionStorage; | ||
|
|
||
| if (tabLocalStorage) { | ||
| tabLocalStorage.setItem(`${config.configId}-${STORAGE_KEY}`, url); | ||
| } else { | ||
| this.storageService.write(STORAGE_KEY, url, config); | ||
| } |
Comment on lines
+238
to
+242
| const originalStorage = Storage; | ||
|
|
||
| (Storage as any) = undefined; | ||
| expect((service as any).hasStorage()).toBeFalse(); | ||
| Storage = Storage; | ||
| (Storage as any) = originalStorage; |
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.
Summary
The auto-login guards save the pending redirect route in the configured storage, which is shared across tabs (e.g. a localStorage
AbstractSecurityStorage) and keyed by the deterministic configId — so concurrent logins in multiple tabs overwrite each other's saved route. The route is now stored per browser tab (sessionStorage).The bug
With a shared storage and two tabs logging in concurrently (same configId, one
redirectslot):/orders/123; tab B's guard overwrites it with/orders/456before the login completes.checkSavedRedirectRouteAndNavigatewhen authenticated.The redirect round trip always returns to the tab that saved the route, so the slot is inherently tab-local state.
The fix
AutoLoginServicewrites the route tosessionStorage(per tab, key<configId>-redirect), accessed viainject(DOCUMENT).defaultViewlike the other window globals in this library:sessionStorageunavailable (SSR) → the previous behavior is kept unchanged.AutoLoginService.Trade-off: a route saved in one tab is no longer restored by a login completing in a different tab — that cross-tab restore was the same mechanism as the overwriting.
Test plan