0

Following on from this question I am trying to set both the currentUser and the account properties in my custom session:

/app/sessions/custom.js

import Ember from 'ember';
import Session from 'simple-auth/session';

export default Session.extend({
  currentUser: Ember.computed('secure.user_id', 'isAuthenticated', function() {
    console.log('currentUser');
    var userId = this.get('secure.user_id');
    if (userId && this.get('isAuthenticated')) {
      return this._store.find('user', userId);
    }
  }),
  account: Ember.computed('currentUser', function() {
    console.log('account');
    this.get('currentUser').then(function(currentUser) {
      return this._store.find('account', currentUser.get('account').id);
    })
  })
});

but for some reason the console.log('account'); is never called. I guess that this is because currentUser is a promise and thus hasn't yet resolved?

Should I return an Ember.RSVP.hash instead?

Community
  • 1
  • 1
Joe Czucha
  • 4,123
  • 2
  • 20
  • 28
  • 1
    Have you tried using a `DS.PromiseObject`? – marcoow Jun 18 '15 at 11:32
  • i think if you try `Ember.computed('secure.user_id', ..)` instead `Ember.computed('currentUser', ...)` it will work – artych Jun 18 '15 at 11:37
  • and you could try promise: `account: Ember.computed('secure.user_id', function() { return this.get('currentUser').get('account') });` this is simpler – artych Jun 18 '15 at 11:41
  • or `account: Ember.computed('secure.user_id', function() { return this.get('currentUser').then(function(user) { return user.get('account'); }); })` if comments above do not work – artych Jun 18 '15 at 12:06
  • Okay I am missing something here! In the above, currentUser outputs the `console.log('currentUser')` correctly. However, if I change it to anything other than currentUser (or add other functions) it doesn't work. This is EVEN if the only thing in the function is `console.log`. I've tried logging but it still only works if called currentUser... >_ – Joe Czucha Jun 18 '15 at 13:07

0 Answers0