这是我第一次使用ember.js。我试图在用户成功登录(经过身份验证)时使用控制器执行操作。但是,我目前的方法是保存用户的状态,甚至更改属性' this.set(' userSignedIn',state);'不管用。我不确定为什么,我猜它与我的状态'的范围有关。变量或者也许是这个'对象未被传递给' ref.authWithOAuthPopup()'。我希望有人能指出正确的方向。
var ref = new Firebase("https://<app>.firebaseio.com");
var state = false;
MyApp.ApplicationController = Ember.Controller.extend({
userSignedIn: false,
actions: {
signin: function() {
ref.authWithOAuthPopup("facebook", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
state = true;
}
});
this.set('userSignedIn', state);
console.log(state);
}, // End of signin
}
});
答案 0 :(得分:1)
在userSignedIn
onComplete回调被触发之前设置Firebase.authWithOAuthPopup(provider, onComplete, [options])
。相反,试试这个:
signin: function() {
controllerContext = this;
ref.authWithOAuthPopup("facebook", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
state = true;
controllerContext.set('userSignedIn', state);
console.log(state);
}
});
}, // End of signin