getAccessTokenSilently won't get me a token

I’m trying to save my token in localstorage, using auth0 onRerirectCallback

  const onRedirectCallback = async (appState) => {
    try {
      const token = await getAccessTokenSilently();
      localStorage.setItem('token', token);
      window.history.replaceState({}, document.title, appState?.returnTo || window.location.pathname);
    } catch (error) {
      console.error(error);
    }
  };

    <Auth0Provider
      domain={domain}
      clientId={clientId}
      redirectUri={window.location.origin}
      onRedirectCallback={onRedirectCallback}
    >
      {children}
    </Auth0Provider>
  );

The functions is called, but I don’t get a token. What am I doing wrong ?

Update:

So I created an /authorize endpoint where with useEffect I capture the token, and it seems to work, but I still do not understand while is not working with the code above.

  useEffect(() => {
    if (isAuthenticated) {
      const getAccessToken = async () => {
        const token = await getAccessTokenSilently();
        if (token) {
          localStorage.setItem('accessToken', token);
          // navigate to the page the user was trying to access before being redirected to login
          navigate('/');

        }
      };
      getAccessToken();
    } else {
      // redirect to login page and clear the token
      localStorage.removeItem('accessToken');
      navigate('/login');
    }

  }, [isAuthenticated]);

Above the bit of extra logic, I had to implement