# How to login once across multiple subdomains on a custom domain?

**URL:** <https://community.auth0.com/t/how-to-login-once-across-multiple-subdomains-on-a-custom-domain/78614>\
**Category:** Get Help\
**Tags:** auth0-subdomain\
**Created:** [February 20, 2022, 5:02am UTC](https://community.auth0.com/t/how-to-login-once-across-multiple-subdomains-on-a-custom-domain/78614 "2022-02-20T05:02:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ianz/32/35346_2.png) [@ianz](https://community.auth0.com/u/ianz)\
**Post date:** [February 20, 2022, 5:02am UTC](https://community.auth0.com/t/how-to-login-once-across-multiple-subdomains-on-a-custom-domain/78614/1 "2022-02-20T05:02:14Z")

</div>

We are developing a suite of separate SPA applications where each one lives on a subdomain with a common parent domain.

```auto
app1.domain.com
app2.domain.com

```

We want to avoid customers having to sign in to each app separately. So we want to be able to sign in once to one app and remaining signed in when visiting the other apps. Similarly, signing out of one would sign out in the others.

Based on my research of the Auth0 docs, this _seemed_ to be possible with a custom domain. So changed our plan, added the custom domain `auth.domain.com` and created a test SPA app that could log in. I then created two subdomains and pointed them both at the app.

Logging in to `app1.domain.com` worked. The `auth0.{clientid}.is.authenticated` cookie was created. However, the cookie’s domain was `app1.domain.com`, not `.domain.com` as I’d hoped.

I then tried visiting the `app2.domain.com` and confirmed that the cookie definitely wasn’t there and I wasn’t logged in.

Is there any way to configure Auth0 to keep a user logged in across all the subdomains?

---

<div class="post-metadata">

**Author:** ![ianz](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ianz/32/35346_2.png) [@ianz](https://community.auth0.com/u/ianz)\
**Post date:** [June 4, 2022, 2:15am UTC](https://community.auth0.com/t/how-to-login-once-across-multiple-subdomains-on-a-custom-domain/78614/2 "2022-06-04T02:15:38Z")

</div>

I opened a [pull request](https://github.com/auth0/auth0-spa-js/issues/884) on `auth0-spa-js` package to add an option to specify the cookie domain. It was accepted and merged. It was accepted and merged in version `1.21.0` and later.

In your client configuration, add a `cookieDomain` option.

```
const auth0 = await createAuth0Client({
  domain: '<AUTH0_DOMAIN>',
  client_id: '<AUTH0_CLIENT_ID>',
  redirect_uri: '<MY_CALLBACK_URL>',
  audience: '<MY_AUDIENCE>',
  cookieDomain: '.example.com',
})

```

**NOTE:** Top level cookie domains always start with a period `.`.

Use this configuration on each app/subdomain under the same top level domain and you’ll notice the `auth0.{clientid}.is.authenticated` cookie will exist on both. Signing in on one will result in you being signed in when you visit any others.

The `auth0-spa-js` package is used by most of the other auth0 plugins for Vue, React, etc. so client configuration should be virtually identical.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 4, 2022, 2:57pm UTC](https://community.auth0.com/t/how-to-login-once-across-multiple-subdomains-on-a-custom-domain/78614/3 "2022-11-04T14:57:31Z")

</div>


