Using meteor login state between subdomains: a meteor 1.3 npm package


#1

Hi there,

For a new project that I am writing in Meteor 1.3 I needed a login state that is persistent between subdomains. Normally when you go to another subdomain (in the same app) the user is not logged in anymore. This is because meteor stores the login token in the local storage and they cannot span subdomains.

In this package I mirror the login token on a cookie, so the user is still logged in even if he accesses the app from another subdomain.

It’s really easy to use this in your Meteor 1.3 app. On the command line run:

npm install --save meteor-subdomain-persistent-login

Then in your main client file put the following code:

import SubdomainPersistentLogin from 'meteor-subdomain-persistent-login'

Meteor.startup(() => {
  const subdomainPersistentLogin = new SubdomainPersistentLogin(Meteor, ['.app.localhost'])
})

Replace .app.localhost with your domain. If you host your app on multiple domains
you can even give a list of domains. However the login will not persist between domains,
because I do not think that is possible with cookies.

Let me know what you think!


#3

The package has a bug in it. The pull request fixes it.