我在我的应用中使用了Meteor.loginWithGoogle。我正在尝试获取谷歌用户的电子邮件地址,以便将其放入Session变量中。
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');
}
});
}
});发布于 2016-04-30 05:49:23
我不确定我是否理解了你的问题,但我猜你想问的是:“在用户执行loginWithGoogle之后,我如何获取他的电子邮件地址,并将其设置到他的会话中?”
登录后,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');
}
});
}
});您可以在:Meteor documentation和http://cs.wellesley.edu/~mashups/pages/meteor6.html中找到更多详细信息
https://stackoverflow.com/questions/36937010
复制相似问题