Cant enable autoLogin without storage: "localstorage"

After reloading my React app lost auth and i need to manually press login button.

  1. I explored that this is due to 3rd party cookies being blocked (cookies were reset) and solved this with specifying autProvider to use localStorage:
<Auth0Provider
      cacheLocation="localstorage"

However i also found out that custom domains may solve this problem. And i added custom domain. Now i have cookies beeing preserved in browser, but if i change cache location to memory there is still no autologin, despite cookies are exist.

How to solve this? Should i invoke special methods in auth sdk? Have auth0 cookies in browser but still need to manually press login button to actually login


I have tried addig this to my app.tsx. But i honestly do not understand, why do i need accessToken when working with SPA, but anyway:

const { getAccessTokenSilently } = useAuth0();
  getAccessTokenSilently().catch((e) => console.error(e));

this returns error:

Error: Missing Refresh Token (audience: '', scope: 'openid profile email offline_access')

Token rotation and other token related stuff enabled in dashboard app settings and in authProvider:

<Auth0Provider
      cacheLocation="memory"
      domain={import.meta.env.VITE_AUTH0_DOMAIN as string} // my custom domain here
      useRefreshTokens={true}
      clientId={import.meta.env.VITE_AUTH0_ID as string}
      authorizationParams={{
        redirect_uri: window.location.origin,
      }}
    >

I also tried to add my standard auth api url to audience:

getAccessTokenSilently({
    authorizationParams: {
      audience: "https://dev-68o3zkhek7iateoYY0i.us.auth0.com/api/v2/",
    },
  }).catch((e) => console.error(e));

Same error but with specified audience.

Tried

audience: `https://MY_CUSTOM_DOMAIN/api/v2/`,

without any results with same error

Hi @skorphil

Thank you for posting your inquiry regarding the issue that you are facing.

I would recommend you to visit our documentation related to Configuring Silent Authentication and our documentation about the SPA SDK which provides info about using Rotating Refresh Tokens and getting the Access Token without interaction.

There is also a Knowledge Article about using Refresh Tokens with React.

Additionally, the audience for the access token needs to be your generic Auth0 tenant URL, you will not be able to use your custom domain as audience.

If you have any other questions or still having issues with implementing refresh tokens, please feel free to leave another reply on the post.

Kind Regards,
Nik

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