fix: ensure isAuthenticated$ has fresh value#671
Open
mrentmeister-tt wants to merge 3 commits intoauth0:mainfrom
Open
fix: ensure isAuthenticated$ has fresh value#671mrentmeister-tt wants to merge 3 commits intoauth0:mainfrom
mrentmeister-tt wants to merge 3 commits intoauth0:mainfrom
Conversation
6 tasks
mrentmeister-tt
commented
Jun 23, 2025
| return of(undefined); | ||
| } | ||
|
|
||
| this.authState.refresh(); |
Author
There was a problem hiding this comment.
Trigger a refresh and wait for it to fully propagate before completing the observable
mrentmeister-tt
commented
Jun 23, 2025
| constructor(@Inject(Auth0ClientService) private auth0Client: Auth0Client) {} | ||
| constructor(@Inject(Auth0ClientService) private auth0Client: Auth0Client) { | ||
| // Subscribe to refreshCompletion$ to ensure refresh state completes | ||
| this.refreshCompletion$.pipe(takeUntil(this.ngUnsubscribe$)).subscribe(); |
Author
There was a problem hiding this comment.
This is here to ensure that we always have at least one subscriber to refreshCompletion$, so that we accurately keep track of the internal state. If we don't do this, then the observable chain to change refreshSubject to Complete might not be invoked.
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
This PR addresses a race condition in the
isAuthenticated$observable that can occur during the login and logout flows. The issue manifests when the application navigates before theisAuthenticated$observable has a fresh value, potentially leading to stale authentication states.Fixes #668
The changes include:
RefreshStateenum to track the state of auth state refresheshandleRedirectCallbackto wait for the refresh operation to complete before navigationlogoutfunction to ensure it waits for the refresh operation to completerefreshComplete$observable to signal when refresh operations are completeThese changes ensure that navigation only occurs after the authentication state has been properly updated, preventing race conditions and stale values in the
isAuthenticated$observable.References
This PR addresses the issue described in DEV-2553, where users were experiencing blank screens during the authentication flow due to race conditions in the
isAuthenticated$observable.Testing
The changes can be tested by:
Testing the login flow:
loginWithRedirect()isAuthenticated$has a fresh valueTesting the logout flow:
logout()Environment:
Angular 13
Node.js 20.15.0
macOS 24.4.0
This change adds test coverage for new/changed/fixed functionality
Checklist