I've an ember-cli app that is using ember-simple-auth.
I created a custom initializer to inject a currentUser object in
import Ember from 'ember';
import Session from 'simple-auth/session';
export default {
name: "current-user",
before: "simple-auth",
initialize: function(container) {
Session.reopen({
setCurrentUser: function() {
var accessToken = this.get('secure.token');
var _this = this;
if (!Ember.isEmpty(accessToken)) {
return container.lookup('store:main').find('user', 'me').then(function(user) {
_this.set('content.currentUser', user);
});
}
}.observes('secure.token'),
setAccount: function() {
console.log(this.get('content.currentUser'));
var _this = this;
return container.lookup('store:main').find('account', this.get('content.currentUser.accountID')).then(function(account) {
_this.set('content.account', account);
});
}.observes('content.currentUser'),
});
}
};
I can access the currentUser properties in my templates with {{session.content.currentUser.email}}
I can't figure out how to access it in the route...
import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
console.log(this.get('session.content')); // valid
console.log(this.get('session.content.currentUser')); // undefined
return Ember.RSVP.hash({
layouts: this.store.find('layout', { account_id: 1}),
});
},
setupController: function(controller, model) {
controller.setProperties(model);
},
});
Can anyone put me out of my misery?
Thanks :)
Aucun commentaire:
Enregistrer un commentaire