TypeError: Cannot read property 'hasValidAuth0Instance' of null

Hello . I am a new user and I have never used auth0 .
when i start my react native app , the app shows me the text ‘loading…’

this is my code i copied it from auth quickstarts but it does not work

import { Button, Text, View, StyleSheet } from “react-native”;
import { useAuth0 } from “react-native-auth0”;

const AuthScreen = () => {
const { authorize, clearSession, user, error, isLoading } = useAuth0();
const onLogin = async () => {
try {
await authorize();
} catch (e) {
console.log(e);
}
};

const onLogout = async () => {
try {
await clearSession();
} catch (e) {
console.log(“Log out cancelled”);
}
};

if (isLoading) {
return (

Loading

);
}

const loggedIn = user !== undefined && user !== null;

return (

{loggedIn && You are logged in as {user.name}}
{!loggedIn && You are not logged in}
{error && {error.message}}

  <Button
    onPress={loggedIn ? onLogout : onLogin}
    title={loggedIn ? "Log Out" : "Log In"}
  />
</View>

);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: “center”,
alignItems: “center”,
backgroundColor: “#F5FCFF”,
},
});
export default AuthScreen;

import { Auth0Provider } from “react-native-auth0”;
import { DOMAIN_AUTH0, CLIENT_ID_AUTH0 } from “@env”;

export default function App() {
return (





);
}

console:

WARN Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property ‘hasValidAuth0Instance’ of null

react-native-auth0 is installed
env variables are correct

I will be happy if you will help me . thank you

I’m assuming that you are using expo go to test the app

It’s not working through expo go javascript - Setting up Auth0 in React Native/Expo - Stack Overflow

1 Like

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