Search code examples
nginxember.jsproxy

Why does ember data store share tokens between 2 web apps my domain?


0

I have 2 differents applications in ember.js both connect to the same api: "host1:3000/appA" and "host2:3001/appB". I use nginx so that the client can access appA and appB through a single domain, that is: "mydomain.com/appA" and "mydomain.com/appB". Everything is correct but the applications are sharing "store" ember objects. So if I login into appA, I also login into appB. How can I prevent session sharing between applications?.

I used this code from nginx, but does't work:

location /appA {
  proxy_pass http://host1:3000;
  proxy_cookie_path /appA /appA;
}

location /appB {
  proxy_pass http://host2:3001;
  proxy_cookie_path /appB /appB;
}

Solution

  • For at least one of your apps you will want to setup a new session-store.

    Create a directory under app called session-stores and create a file named application.js.

    The content of this file should be something like this

    import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive';
    
    export default class ApplicationSessionStore extends AdaptiveStore {
      cookieName = 'your-app-name-cookie';
      localStorageKey = 'your-app-name-token';
    }
    

    This will keep the two apps session data completely separate under a different key. If you're not using the adaptive store (you probably are) then you would extend from the store you are using.