@alina1 From the Auth0 React Quickstart docs, I found the following
Ensure that the SDK has completed loading before accessing the
isAuthenticated
property, by checking thatisLoading
isfalse
.
@auth0/auth0-react has sample code to show isLoading
+ isAuthenticated
to determine to show the Login button or Logout button
// src/App.js
import React from 'react';
import { useAuth0 } from '@auth0/auth0-react';
function App() {
const {
isLoading,
isAuthenticated,
error,
user,
loginWithRedirect,
logout,
} = useAuth0();
if (isLoading) {
return <div>Loading...</div>;
}
if (error) {
return <div>Oops... {error.message}</div>;
}
if (isAuthenticated) {
return (
<div>
Hello {user.name}{' '}
<button onClick={() => logout({ returnTo: window.location.origin })}>
Log out
</button>
</div>
);
} else {
return <button onClick={loginWithRedirect}>Log in</button>;
}
}
export default App;
I hope this helps resolve your issue!