Hi, I have my a ReactJs App based in the QuickStart that Auth0 recommends here(Auth0 React SDK Quickstarts: Login), the problem that I have been facing is that in my react component I have something like this:
import React from "react";
import { useAuth0 } from "../react-auth0-spa";
import authProvider from '../authProvider'
import LoginForm from '../components/LoginForm'
const LoginPage = () => {
const { isAuthenticated, loginWithRedirect } = useAuth0();
return (
<div>
{!isAuthenticated && (
<LoginForm/>
)}
{isAuthenticated &&
<div> you are logged in</div>
}
</div>
);
};
export default LoginPage;
so where is the problem?
when I refresh the page it log me out automatically, and I’ve been reading a lot of forums trying to get an answer, I read that using getTokenSilently function will works to solve this problem, the thing is that when I call that function I get an error, saying:
“TypeError: Cannot read property ‘getTokenSilently’ of undefined”
and I don’t know, how can the app knows that I’ve logged in so when I refresh the page it stills having me inside my app.
Where in your code do you call the getTokenSilently() and how?
There’s a github issue about the same error message, not sure if you’ve checked that and the comments on there already, maybe they’re relevant for your case as well.
It is suppossed that auth0 manage in it owns the getTokenSilently when the page is refreshed, I’ll describe each step to reproduce the error I’m getting: