2016-09-09 2 views
-1

처음에는 반응 변수를 사용하는 조건이있는 페이지가 있지만 페이스 북 또는 Google을 사용하여 로그인하면 페이지 내용이 변경되고 페이지의 내용이 변경됩니다.유성 로그인 wiogleGoogle 문제

페이스 북을 사용하여 로그인 할 때 모든 것이 잘되지만 Google을 사용하여 로그인 할 때 변수 isAuthenticated가 true로 변경되지 않지만 다른 페이지로 이동하면 사용자가 로그인 할 때 나타납니다 무슨 일이 일어나고 있는지 내가 할 때 (Meteor.userId()) 구글과 인증 아직 완료되지 않습니다, 그래서이 단계를 건너 뛰고 변수의 값을 변경하지 않습니다. 인증이 완료 될 때까지 어떻게 기다릴 수 있습니까? . 내가 사용자가 처음에 로그인하지 않은 경우 그 다음, 그것은 단지 나던 작업 조건을 입력 구글에 로그인 다시 클릭하면

을이 구글 방법을 내 로그인은 다음과 같습니다

'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.loginWithGoogle 기능에 ReactiveVar을 설정할 수 없습니다

답변

2

우선이

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 {} 
}); 

} 
시도