Enable Cross-Domain Login with Memberstack

Article author
Josh Lopez

Cross-domain login is a great new feature available with Memberstack. It allows your members to stay logged in as they navigate across your different domains that have Memberstack installed.

For example, a member can log into yoursite.com and then go to app.yoursite.com without having to log in again. This creates a unified experience across all of your websites.

For example:

  • A member logs into yoursite.com
  • They then go to app.yoursite.com
  • They are still logged in!

Cross-domain login creates a seamless, unified experience for your members.

Follow these steps to enable it:

1. Set up Custom Domains

First, you need to have Custom Domains configured in Memberstack. This allows you to use Memberstack across multiple domains.

2. Update your Header Scripts

Add the following code above the memberstack install script on both websites. Don't delete the memberstack install script!

<script>
const memberstackConfig = {
  useCookies: true,
  setCookieOnRootDomain: true
}
</script>

This enables two key options:

  • useCookies - Uses cookies for session management across domains.
  • setCookieOnRootDomain - Sets the cookies on the root domain to allow access across subdomains.

If you are only using the DOM Package you can add the two properties to the init function to enable this as well.

memberstackDom.init({
    ...
    useCookies: true
    setCookieOnRoot: true
})

And that's it! Cross-domain login will now work across your Memberstack sites. Members can seamlessly navigate without re-logging in.

Was this article helpful?

Comments

6 comments

  • Comment author
    Suhail Razzak

    Josh Lopez when will this be available in the memberstack/dom package? thanks.

    0
  • Comment author
    Josh Lopez

    Hey Suhail Razzak 👋

    It is available now! In the init function you would need to add two additional properties like:

     memberstackDom.init({
        ...
        useCookies: true
        setCookieOnRoot: true
    })
    0
  • Comment author
    Suhail Razzak

    Thank you! Will check it out 👍

    0
  • Comment author
    Antoine Charrier

    Hello I'm almost there thanks for this feature, but now I want to GATE the entire subdomain. How to do it please ?

     

    0
  • Comment author
    Artem Avramenko

    When I add the script I get "Access blocked: This app's request is invalid" error when using Google SSO. Also website becomes not secure in the browser.

    I think this is because I have a reverse proxy and it breaks something. 
    (Custom domain was set up correctly and it works just fine)

     
    0
  • Comment author
    Jon Worek

    Hi Josh. Thanks for putting together this guide. Have you tested this with the React package? https://developers.memberstack.com/docs/react-package#memberstack-provider

    I might have expected that you could pass in the same two config options as you would to memberstackDom:

    memberstackDom.init({
        ...
        useCookies: true
        setCookieOnRoot: true
    })

    when initializing the <MemberstackProvider config={config}/> but it doesn't seem to have an effect. The `_ms-mid` cookie is still getting written for the subdomain, and not the root domain.

    0

Please sign in to leave a comment.