User management in split-app architecture


#1

I am building an app using the “seperate app” or “microservice” type of technique/structure which seems to have been discussed more and more lately.

My goal is to completely seperate the admin backoffice from the public facing app, so I have an an “admin app” and a “public app”…

My (simplified) directory structure looks like this:

MyApp/
  Admin/
    .meteor/
  App/
    .meteor/

My reasons for this split are as follows:

  • Large amount of packages, templates and code which I dont want bundled with the main app
  • No need for admin security checks and conditionals all over main app code
  • Completely different user accounts setup for admin app
  • Admin app can be hosted on a seperate server not accessable to the public
  • Admin app can be built into seperate mobile app for admin users only

So far, I have the 2 apps up and running and sharing the same DB. Each app is using a seperate collection for users which is achieved with the following in the admin app:

Accounts.users = new Mongo.Collection("admin_users", {
    _preventAutopublish: true
});

Meteor.users = Accounts.users;

However I am now trying to implement user management in the admin app which will allow admin users to CRUD users in the main app and things are starting to get a bit complicated.

Before going into detail about the specific things Ive tried and issues Ive encountered, I’d like to get some feedback from others which have tried similar approaches or have suggestions on alternative approaches. Am I wondering to far off the path or am I still heading in a good direction here?

Any feedback would be greatly appreciated.

Thanks


#2

To answer my own question, the Meteor docs actually have a section specifically about this type of Accounts sharing between apps - https://guide.meteor.com/structure.html#sharing-accounts

The example in the docs only shows how to login from the client. My issue is that I am trying to create a user in the main app, from the admin app, on the server side using Accounts.createUser.

I have tried the following (simplified):

const publicApp = DDP.connect('url://of.public.app');
const publicAccounts = new AccountsServer(publicApp);
publicAccounts.createUser();

but I get the following error:

Error: There is already a collection named “users”