Ember.js 身份验证操作无效

Ember.js authentication action not working

这是我第一次使用 ember.js。当用户成功登录(通过身份验证)时,我正在尝试使用控制器执行操作。但是,我当前保存用户状态甚至更改 属性 'this.set('userSignedIn', state);' 的方法不管用。我不确定为什么,我猜这与我的 'state' 变量的范围有关,或者可能 'this' 对象没有传递给 '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



}
});

您在触发 Firebase.authWithOAuthPopup(provider, onComplete, [options]) onComplete 回调之前设置了 userSignedIn。相反,试试这个:

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