Search code examples
authenticationmeteorsubdomainscale

Login to meteor set database redirect subdomain


I like to build a to do list for multi company on one server. I build a to do list, but now I like to "scale" to app to different "sub servers"

I like to explain it by this example

Start: example.com - There is a login button. When you enter your account you are redirect to a subdomain

company1.example.com Here is the to do list for company 1. This company uses his own database for example mongodb://localhost:27017/compagny1

When I direct go to company1.example.com without a login I will be redirected to example.com

I this possible or is there a other way to set user and database for meteor. I don't like to have multi servers for example: localhost:3001 localhost:3002 etc

Thank you for giving me a direction for this question


Solution

  • I would do something similar:

    add user field to store company name. (eg. user.company = company1)

    use iron router and put a onBeforeAction to the page that user is redirected after login

      onBeforeAction: function (pause) {
            if (Meteor.user()) {   // only if user is logged in
                var comp = Meteor.user().company
                if(comp == 'company1'){
                   this.render('company1'); // will render example.com/company1 if setup
                }
    
            // pause this rendering of the rest of the before hooks and the action function 
            pause();
          }
        },
    

    Update: i do not think many databases would be great. I better recomend making separate collections for each companys todos and subscribe them individually.