Skip to content

OidcAuthProvider briefly returns null after login, causing navigation tree to unmount #7

@Sam-Lam-Varadise

Description

@Sam-Lam-Varadise

What's happening

When a user logs in for the first time in a fresh session, the app crashes with:

Cannot read property 'stale' of undefined

The error originates from StackRouter.js inside expo-router / react-navigation, because the navigation state becomes undefined mid-transition.

Root cause

In OidcAuthProvider, the isLoading condition is:

const isLoading = isInitializing &&
  (isUserFetchSuccess || isUserFetchError || !isAuthenticated);

The problem is the timing right after a successful login:

  1. isAuthenticated flips to true
  2. isUserFetchSuccess and isUserFetchError are still false (the getUserInfo() fetch is in-flight)
  3. The condition evaluates to false → provider returns null
  4. The entire child tree (including the navigation stack) unmounts
  5. Once getUserInfo() resolves, isLoading becomes true again and the tree remounts with a fresh/empty navigation state
  6. The navigation stack receives state = undefined during the remount → crash

Reproduction

  • Use OidcAuthProvider with a stack navigator (e.g. expo-router)
  • Start the app fresh (no cached session)
  • Log in — the crash occurs consistently on the login → authenticated transition

Fix

Simplifying the condition to:

const isLoading = isInitializing;

Once the initialization is complete and isAuthenticated is set, the provider should keep rendering its children regardless of whether the user info fetch has finished. The user info can load in the background without tearing down the navigation tree.

This is what we're using as a local patch in our project (react-native-oidc-auth-core@0.1.3) and it resolves the issue.

Environment

  • react-native-oidc-auth-core: 0.1.3
  • react-native-oidc-auth-expo: 0.1.3
  • expo-router: ~55.0.3
  • react-native: 0.83.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions