# Best practice for storing authenticated user's data

**URL:** <https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418>\
**Category:** Design\
**Created:** [March 7, 2014, 4:16pm UTC](https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418 "2014-03-07T16:16:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Costent](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/costent/32/3984_2.png) [@Costent](https://discuss.emberjs.com/u/Costent)\
**Post date:** [March 7, 2014, 4:16pm UTC](https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418/1 "2014-03-07T16:16:44Z")

</div>

Hello,

I’m looking for the best way to store my authenticated user’s informations. Basically is an Ember.Object instance (could be an Ember.ObjectController instance as well) that saves basic user’s informations (id, name, email, etc). This object has to be reachable from all controllers and routes (to deal with access level and to display user specific informations for example). Nowadays, I store this object in the App global (something like App.user). I would like to know what’s your solution and if there is better way to do that. Especially, I’m asking myself if it would be better to store the user in the App.\ __container\__ to “legally” access the user from controllers and routes (this.container.user).

---

<div class="post-metadata">

**Author:** ![codefox421](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/codefox421/32/14885_2.png) [@codefox421](https://discuss.emberjs.com/u/codefox421)\
**Post date:** [March 7, 2014, 5:54pm UTC](https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418/2 "2014-03-07T17:54:16Z")

</div>

Maybe the application controller would be the place for this:

```auto
App.ApplicationController = Ember.Controller.extend({
  user: // user data goes here
});

App.OtherController = Ember.Controller.extend({
  needs: ['application'],
  // use it with:
  userBinding: 'controllers.application.user',
  // or with:
  userProperty: function() {
    return this.get('controllers.application.user');
  }.property('controllers.application.user'),
  // etc...
});

```

---

<div class="post-metadata">

**Author:** ![rmbrad](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rmbrad](https://discuss.emberjs.com/u/rmbrad)\
**Post date:** [March 7, 2014, 11:13pm UTC](https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418/3 "2014-03-07T23:13:55Z")

</div>

In our apps we have a Session object that we inject into all controllers and routes, something like this:

```
App.initializer({
  name: 'session',
  initialize: function(container, application) {
    container.register('app:session', App.Session);

    container.injection('controller', 'session', 'app:session');
    container.injection('route', 'session', 'app:session');
  }

```

---

<div class="post-metadata">

**Author:** ![thapa\_abhay](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/thapa_abhay/32/15360_2.png) [@thapa\_abhay](https://discuss.emberjs.com/u/thapa_abhay)\
**Post date:** [March 9, 2014, 9:37am UTC](https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418/4 "2014-03-09T09:37:09Z")

</div>

The offical api is `container.injection` not container.typeInjection. [Check the docs](http://emberjs.com/api/classes/Ember.ControllerMixin.html#method_injection)

---

<div class="post-metadata">

**Author:** ![rmbrad](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@rmbrad](https://discuss.emberjs.com/u/rmbrad)\
**Post date:** [March 9, 2014, 7:41pm UTC](https://discuss.emberjs.com/t/best-practice-for-storing-authenticated-users-data/4418/5 "2014-03-09T19:41:00Z")

</div>

Thanks for the information (I’ve updated the code in the example accordingly). I just copied and pasted from an old app that was written before the container was documented. Regardless of API, I still think that using injection is a clean solution to the stated problem, and was really looking for feedback as to whether or not there was a better solution.
