I already saw some examples about realising a session in ember with a Router approach, but also some statements about simply using the StateManager.
Given that I have a Restful backend, I have to send my credentials every time to my service. For that I simply want to store the credentials in a session at the frontend. Should I just store the credentials in a "LoggedIn" state of the StateManager
or use another approach?

- 14,900
- 10
- 82
- 107
1 Answers
You should isolate your needs, as it seems to me you are trying to address two aspects here:
- Authentication, passing credentials to your backend,
- Authenticated state & attributes.
BTW, even if you are simply intending to manage first point, the following will still apply... :-)
Ember is really good at managing your app's state w/ router & al.
But when speaking about authentication, it is something that have to deal with backend and has almost nothing to see with your SPA state. It's a kind of transversal issue, not to be managed by your Ember router instance at all, IMO (and I am not alone: see this tweet & replies). You should so manage the auth outside the Ember app, even before serving the SPA, using stuff like Devise
, Sorcery
, ...
This being said, once you have a session established between your browser & the backend, your will be able to include statically some data from your logged user inside the page, which will be accessible to your app for use (user name, profile data, ...).
If you really still want to manage logged-(in/out) state in your router, you can also have a look at this answer, but I finally changed my mind on this topic, as I explained before.
-
how to store authenticated state and attributes? In my App I've done authentication with backend and I only have a cookie. But User can also choose group. This group is correlated with every state in my route. This is big problem for such beginer as me – SiMet Oct 30 '12 at 20:26
-
1You can send the user back to the browser when rendering the application HTML page on server side: add a ` – Mike Aski Oct 31 '12 at 08:07