Ember.js身份验证操作不起作用

Ember.js authentication action not working

本文关键字:不起作用 操作 身份验证 js Ember      更新时间:2023-09-26

这是我第一次使用余烬.js。我正在尝试使用控制器在用户成功登录(经过身份验证)时执行操作。但是,我当前保存用户状态甚至更改属性"this.set('userSignedIn', 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

}
});
您在触发

onComplete 回调之前设置Firebase.authWithOAuthPopup(provider, onComplete, [options]) 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