I have a React Native v0.75.4 application built with the React Native CLI where I’m implementing the passwordRealm login method then saving credentials using the credentialsManager.
The passwordRealm call is successful and returns a credentials object, but when trying to save it using the credentialsManager saveCredentials method, it throws the following error:
[a0.credential_manager.invalid: Cannot read property 'hasValidAuth0Instance' of null]
The version of the react-native-auth0 SDK in package.json is: "react-native-auth0": "^3.2.1"
The code in my application is below:
import Auth0 from 'react-native-auth0';
const auth0 = new Auth0({
domain: DOMAIN, // uses real value
clientId: CLIENT_ID, // uses real value
});
export const login = async (username: string, password: string) => {
try {
const credentials = await auth0.auth.passwordRealm({
username,
password,
realm: config.realm,
scope: config.scope,
});
await auth0.credentialsManager.saveCredentials(credentials); <- error
} catch (err) {
console.log(err);
}
};
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.
This SDK is not compatible with “Expo Go” app. It is compatible only with Custom Dev Client and EAS builds.
You can also try to change the iOS target deployment version to 13.0 in the podfile if you are using an iOS environment/simulation.
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: