TypeError: can't access property "hasValidAuth0Instance", nativeModule is undefined

I’m trying to setup Authentication going through this tutorial: Auth0 Expo SDK Quickstarts: Login

The Login is working when running expo run:android

The Android App runs, and redirects properly to the Login Page, afterwards I log in using my auth0 account and it redirects me back properly to Android, I can see the Token and read the information in it (Email, etc). All good on this side

However the Web version runs (expo start --web) but is stuck on Loading…, in the Console in my browser I find this:

Uncaught (in promise) TypeError: can't access property "hasValidAuth0Instance", nativeModule is undefined
    _ensureNativeModuleIsInitialized2 nativeHelper.js:5
    Babel 4
        asyncGeneratorStep
        _next
        _asyncToGenerator
        _asyncToGenerator
nativeHelper.js:5:10
    Babel 6
        asyncGeneratorStep
        _throw
        (Async: promise callback)
    asyncGeneratorStep
        _next
        _asyncToGenerator
        _asyncToGenerator
    Auth0Provider auth0-provider.js:78
    React 11
    (Async: EventHandlerNonNull)
    <anonymous> AppEntry.bundle:11666
    <anonymous> React
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> React
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    React 2
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> React
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> index.js:2
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> index.js:14
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> registerRootComponent.js:3
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> AppEntry.js:5
    loadModuleImplementation require.js:283
    guardedLoadModule require.js:182
    metroRequire require.js:91
    <anonymous> AppEntry.bundle:67210

Thanks in advance for any help!

1 Like

Did you find a solution to this? I am facing the same thing @serafdev

same here, anybody able to fix this?

Any updates on this? I’m getting it with Expo, react-native-web, and expo-router

The docs don’t really account for expo router so I was wondering if that is part of the issue

What did you end up doing?

I had to change the ios target deployment version to 13.0 in my podfile, then auth0 worked

Hi @serafdev

Welcome to the Auth0 Community!

I am sorry about the late reply to your inquiry.

As far as I have checked, the hasValidAuth0Instance error that you are receiving seems to be specific when you are using Expo Go with your React Native Application.

As mentioned on our SDK page:

This SDK is not compatible with “Expo Go” app. It is compatible only with Custom Dev Client and EAS builds.

Alternatively, you might be missing the audience parameter in the authorize() call. You would have to pass the audience parameter when you make the call as follows:

const onLogin = async () => {
    try {
      await authorize({ audience: 'https://test.api'});
      let credentials = await getCredentials();
      Alert.alert('AccessToken: ' + credentials.accessToken);
    } catch (e) {
      console.log(e);
    }
  };

This code is referenced here: react-native-auth0/src/hooks/tests/use-auth0.spec.jsx at e1771491969934cc20dd3ed0e8beeb6c5cf70577 · auth0/react-native-auth0 · GitHub

Also, you might be missing some kind of configuration specific from our React Native SDK.
If you run npx create-react-native-app, you may have to configure native code differently than if you had built using the npx create-expo-app . The two scripts produce slightly different gradle files from what I can tell.

My personal advise would be to switch to Custom Dev Client and EAS builds, even if it is inconvenient

If you have any other questions on the matter or found a solution to it already, feel free to let us know by leaving a reply!

Kind Regards,
Nik

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.