【发布时间】:2015-09-18 15:45:27
【问题描述】:
我有一个咖啡订购应用程序,正在尝试将用户连接到他们的商店。
我正在对用户进行身份验证,然后在基于 ember-simple-auth 的会话中设置该用户。该部分可以很好地设置 session.currentUser 属性,但我也想设置 session.myStore 对象,但我遇到了问题。
现在我在初始化器中做这一切:
// initializers/custom-user.js
export default {
name: 'current-user',
before: 'simple-auth',
initialize: function(container, application) {
Session.reopen({
setCurrentUser: function() {
let appController = container.lookup("controller:application");
application.deferReadiness();
if(this.get('isAuthenticated')) {
let store = container.lookup('store:main');
let _this = this;
return store.find('user', 'me').then((user) => {
// set the current user to be used on the session object
this.set('currentUser', user);
}).then(function(){
// set the store for the current user
store.find('store', {'user': _this.get('currentUser.id')}).then((data) => {
console.log(data);
_this.set('myStore', data);
application.advanceReadiness();
});
})
}
}.observes('isAuthenticated')
});
}
};
我正在将数据返回到我拥有console.log(data); 的位置,但我认为这不是正确的对象。它返回的是类而不是对象。在其他路线/控制器中,我希望能够返回类似 this.get('session.myStore.id') 的内容,但 session.myStore 没有我正在寻找的数据
【问题讨论】:
标签: javascript ember.js ember-simple-auth