Remote users collection with multiple apps

Is there a way to have multiple meteor apps and share only the users collection from one app? To me clear I don’t want all my apps to use the same mongo database. I want them to all have their own individual databases and use one of the app’s users collection to authenticate against.

Currently I am doing this:

__meteor_runtime_config__.ACCOUNTS_CONNECTION_URL = 'http://myurl';

if (Meteor.isClient) {

  Meteor.startup(function() {
    var token = Accounts._storedLoginToken();
    console.log(token);
     if(token)  {
       Meteor.loginWithToken(token, function(err){
        // this is going to throw error if we logged out
        if(err)
          console.log(err);
        else
          console.log('loginWithToken');
      });
     }
  });
}

Which is working on the client, but I have server side code that isn’t working in a publication. The user is null?

Meteor.publish('modules', function() {
    var user = this.userId;
    // This is null here...
  });
}

I think I’ve read about every article on the topic about Accounts in Meteor and I’m confused to say the least. AccountsCommon, AccountsClient and AccountsServer aren’t very clear.

Any help is appreciated…

If you have figured this out, can you please update here as well. I am also looking for similar approach.

Man, quite the old, dusty thread you resurrected there…

You’re not tackling the problem the right way. Here’s a good start: Share login state between microservices

1 Like