gpt4 book ai didi

javascript - ember 根据经过身份验证的用户设置用户对象

转载 作者:行者123 更新时间:2023-12-03 08:51:26 25 4
gpt4 key购买 nike

我有一个咖啡订购应用程序,正在尝试将用户连接到他们的商店。

我正在对用户进行身份验证,然后在基于 ember-simple-auth 的 session 上设置该用户。该部分可以很好地设置 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); 的位置获取数据,但我认为它不是正确的对象。它返回的是类而不是对象。在其他路由/ Controller 中,我希望能够返回类似 this.get('session.myStore.id')session.myStore 没有数据我正在寻找

最佳答案

根据documentation ,“then 的返回值本身就是一个 promise 。第二个‘下游’ promise 通过第一个 promise 的履行或拒绝处理程序的返回值来解决”。那么理论上有可能第一个promise被拒绝,没有获得用户等等_this.get('currentUser.id')未定义。我建议您使用 console.log 检查这一点在第一个 then 的处理程序中打电话。

关于javascript - ember 根据经过身份验证的用户设置用户对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32656087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com