Losing user after redirecting to subdomain auth0-spa-js

Hello everyone!

I know this was asked before but I couldn’t find an answer that works for me…

I am working on a ReactJs application that uses Auth0 for authentication with the auth0-spa-js library. I am using the login with redirect method for authentication and I call the handleRedirectCallback() method on the redirect url.

The problem is that when I try to redirect the user to subdomain, I lose the authentication and the user have to authenticate again. I am doing the login on https://test.com and when I try to redirect to https://subdomain.test.com and I call auth0Client.isAuthenticated() it returns false even though the user just authenticated on the main host.

I was looking at solutions such as SSO and Custom Domains, but I don’t really think I need them as I read many comments where people say that it works out of the box. I added the subdomains with domain placeholders in my app’s settings.

I am looking for suggestions as I am really confused. I will attach code if needed.

Thank you!

1 Like

Hey did you figure out a solution for this? I am experiencing the same issue.

Hello @levidworkin,

If you are experiencing the same issue, try this. Add these properties to your createAuth0Client.

  1. useCookiesForTransactions: true
  2. cookieDomain: ".YOUR_DOMAIN"

Explanation:

useCookiesForTransactions: Set this to true to store pre-login details in cookies. By default, this is false, storing data in sessionStorage, which isn’t accessible across different tabs.

cookieDomain: Specify .YOUR_DOMAIN to seamlessly share cookies across all subdomains. For instance, with cookieDomain: ".example.com", cookies will be shared among sub1.example.com and sub2.example.com.

These configurations ensure a consistent user experience across multiple tabs and subdomains.

1 Like

Thank you @nandan.bhat for concise response.

Thank you, this solved the issue!

1 Like