将Meteor.loginWithGoogle的电子邮件地址放入会话变量中

将Meteor.loginWithGoogle的电子邮件地址放入会话变量中,meteor,Meteor,我正在我的应用程序中使用Meteor.loginWithGoogle。我试图获取google用户的电子邮件地址,将其放入会话变量中 Template.login.events({ 'click #google-login': function(event){ Meteor.loginWithGoogle({}, function(err){ if ( err ) { throw new Meteor.Error("Google login failed")

我正在我的应用程序中使用Meteor.loginWithGoogle。我试图获取google用户的电子邮件地址,将其放入
会话
变量中

Template.login.events({
  'click #google-login': function(event){
    Meteor.loginWithGoogle({}, function(err){
      if ( err ) {
        throw new Meteor.Error("Google login failed");
      } else {
        const emailAddress = ?; // how do I get this from google?
        Session.set('email',emailAddress);
        Router.go('/profile');
      }
    });
  }
});

我不确定我是否理解你的问题,但我猜你想问的是:“在用户使用谷歌登录后,我如何获取他的电子邮件地址,并将其设置到他的会话中?”

登录后,
Meteor.user()
保存当前用户文档。考虑到这一点:

const currentUser = Meteor.user();
const userGoogleServiceMain = currentUser.services.google.email;
这样,您就可以:

Template.login.events({
  'click #google-login': function(event){
    Meteor.loginWithGoogle({}, function(err){
      if ( err ) {
        throw new Meteor.Error("Google login failed");
      } else {
        const currentUser = Meteor.user();
        const emailAddress = currentUser.services.google.email;
        Session.set('email',emailAddress);
        Router.go('/profile');
      }
    });
  }
});

您可以在中找到更多详细信息,

很乐意为您提供帮助。如果这是正确答案,您可能需要标记它