mardi 29 mars 2016

Ember.js -- how to access data in Ember session from route

Using ember-simple-auth I set up a session and set the currentUser key equal to the user object returned from the server:

setCurrentUser: function () {
    if (this.get('isAuthenticated')) {
        const accountId = this.get('session.content.authenticated.user_id');
        this.get('store').findRecord('user', accountId).then(user => {
            this.set('currentUser', user);
        });
    }
}.observes('isAuthenticated')

Problem is when I am trying to access the 'currentUser' key from a route for a data relation:

user: Ember.computed(function(){
    console.log(this.get('session'));
    //return `${this.get('session.currentUser')}`;
  }),

In the console I see (in addition to a bunch of other stuff):

 currentUser: Class 

but if I try to log 'session.currentUser' I am seeing undefined.

What can I do to access the user ID from this route? Having a lot of trouble with this! Thanks in advance :D




Aucun commentaire:

Enregistrer un commentaire