Search code examples
ember.jsstateember-simple-auth

Store application state other than user


I am familiar with the method of using an initializer to inject the current user into the ember-simple-auth created session object and am using is successfully. How would I go about storing/persisting other application states for the logged in user?

For example, in my application we have workspaces. A user can have many workspaces, and we need to define which workspace they're currently signed into. During a session, the user should be able to "sign-out" of the workspace and choose a different one. We also may need to store the id of the workspace they last signed into.


Solution

  • You can store anything you want in the session (as long as it's something that survives a JSON.stringify/JSON.parse roundtrip), e.g. in your routes:

    this.get('session').set('currentWorkspaceId', workspace.get('id'));