auth0-angular icon indicating copy to clipboard operation
auth0-angular copied to clipboard

fix: ensure isAuthenticated$ has fresh value

Open mrentmeister-tt opened this issue 8 months ago • 0 comments

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 the isAuthenticated$ observable has a fresh value, potentially leading to stale authentication states.

Fixes #668

The changes include:

  • Introduction of a RefreshState enum to track the state of auth state refreshes
  • Modification of handleRedirectCallback to wait for the refresh operation to complete before navigation
  • Updates to the logout function to ensure it waits for the refresh operation to complete
  • Addition of a refreshComplete$ observable to signal when refresh operations are complete

These 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:

  1. Testing the login flow:

    • Call loginWithRedirect()
    • After redirect, verify that navigation only occurs after isAuthenticated$ has a fresh value
    • Verify no blank screens appear during the transition
  2. Testing the logout flow:

    • Call logout()
    • Verify that the operation completes only after the refresh operation is done
    • Verify no race conditions occur during the transition

Environment:

  • Angular 13

  • Node.js 20.15.0

  • macOS 24.4.0

  • [x] This change adds test coverage for new/changed/fixed functionality

Checklist

  • [] I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • [] All active GitHub checks for tests, formatting, and security are passing
  • [x] The correct base branch is being used, if not the default branch

mrentmeister-tt avatar May 06 '25 17:05 mrentmeister-tt