Meteor登录与谷歌问题

Meteor登录与谷歌问题,meteor,meteor-accounts,Meteor,Meteor Accounts,我有一个页面,其条件使用了一个最初为false的被动变量,但是当您使用facebook或google登录时,它会变为true,页面内容也会发生变化 当我使用facebook登录时,一切都进行得很顺利,但当我使用google登录时,变量“isAuthenticated”不会变为true,但如果我导航到另一个页面,它会显示为用户已登录,所以我想发生的事是,如果(Meteor.userId())与google的身份验证尚未完成,那么当我登录时,因此它跳过了这一步,并且不改变变量的值。如何等待身份验证完

我有一个页面,其条件使用了一个最初为false的被动变量,但是当您使用facebook或google登录时,它会变为true,页面内容也会发生变化

当我使用facebook登录时,一切都进行得很顺利,但当我使用google登录时,变量“isAuthenticated”不会变为true,但如果我导航到另一个页面,它会显示为用户已登录,所以我想发生的事是,如果(Meteor.userId())与google的身份验证尚未完成,那么当我登录时,因此它跳过了这一步,并且不改变变量的值。如何等待身份验证完成?如果我再次点击谷歌登录,它就会进入状态,只有当用户最初没有登录时,它才不起作用

这是我用谷歌方法登录的:

 'click #google-login': function(event) { 
        event.preventDefault();
        Meteor.loginWithGoogle({}, function(err){
            if (err) {
                return swal({
                    title: "Google Login Failed",
                    timer: 1700,
                    showConfirmButton: false,
                    type: "error"
                });                
                throw new Meteor.Error("Google login failed");
                Template.instance().authenticated.set(false);
            }
        });
            if(Meteor.userId()){
            //Enable idea submission
            Template.instance().authenticated.set(true);
            }
            //Update last login 
            Meteor.users.update( { _id: Meteor.userId() }, {$set: {"metadata.lastLoginAt": new Date()}});
    }

任何帮助都将不胜感激

首先,您不能在meteor.login中使用Google函数设置ReactiveVar,请尝试以下操作

Tracker.autorun(function(){ 
  if (Meteor.userId()) {
  //Enable idea submission
  Template.instance().authenticated.set(true);
//Update last login 
  Meteor.users.update({
      _id: Meteor.userId()
  }, {
      $set: {
          "metadata.lastLoginAt": new Date()
      }
  });
 }
});

'click #google-login': function(event) {
event.preventDefault();
var self = Template.instance();
Meteor.loginWithGoogle({}, function(err) {
    if (err) {
        return swal({
            title: "Google Login Failed",
            timer: 1700,
            showConfirmButton: false,
            type: "error"
        });
        throw new Meteor.Error("Google login failed");
        self.authenticated.set(false);
    } else {}
});

}

首先,你不能在meteor.loginWithGoogle函数中设置ReactiveVar,试试这个

Tracker.autorun(function(){ 
  if (Meteor.userId()) {
  //Enable idea submission
  Template.instance().authenticated.set(true);
//Update last login 
  Meteor.users.update({
      _id: Meteor.userId()
  }, {
      $set: {
          "metadata.lastLoginAt": new Date()
      }
  });
 }
});

'click #google-login': function(event) {
event.preventDefault();
var self = Template.instance();
Meteor.loginWithGoogle({}, function(err) {
    if (err) {
        return swal({
            title: "Google Login Failed",
            timer: 1700,
            showConfirmButton: false,
            type: "error"
        });
        throw new Meteor.Error("Google login failed");
        self.authenticated.set(false);
    } else {}
});

}