fix: ensure isAuthenticated$ has fresh value #671
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:
RefreshState
enum to track the state of auth state refresheshandleRedirectCallback
to wait for the refresh operation to complete before navigationlogout
function 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