Advices for removing multitenancy approach in a meteor app


I am currently using a multitenancy approach in my application, I have forked the initial package because I wanted a user to have access to multiple groups.

But because we add a _groupId fields on the user collection every things is reactive, so I can’t have two tabs with different group views.

I want to find a clean ( and easy ) way to get out of this limitation.

First thought I rewrite subscriptions with a params :
Mysub.subscribe(args) -> Meteor.subscribe(groupId, args)

But I do not know an easy way with methods, do you ?

You could supply the groupId at login (and track lastGroupId for usability), then track the groupId on the connection at the server. This requires the least modification of existing code and was the route we chose - however I wouldn’t recommend doing it, intercepting login to provide custom arguments is REALLY hard. The actual login is fine, but resume sucks - so if you have people moving between computers it causes problems.

In a clean project we’ve started working on, we went the route of ensuring that a groupId is passed with ALL methods and publications, the server still controls the security “can user X do action Y in group Z”, but the client tells us which group they are trying to perform the action on, so no need to track connection specific groupIds.

This is trivial to implement for custom methods/publications, if you use packages that require publications/methods, where you have no control over where they are called (can’t think of any off the top of my head) you may have trouble here, and if you utilise client side insert/update/remove calls e.g., Collection.update({ _id: ""}, {...}) you’ll need to provide custom mutator methods for these, as the deaults require that ONLY an _id is set, and that it is a string. We modified these to require a groupId, and allow for additional selectors - _id is still required, but you can now do things like this:

Collection.update({_id: "test", groupId: "group", "someArray.someField":"someValue"}, {$set: {"someArray.$.someField": "someOtherValue"}})

1 Like