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

时间:2016-04-29 11:19:56

标签: meteor

我在我的应用中使用meteor npm。我正在尝试将google用户的电子邮件地址放入npm变量中。

meteor npm install --save material-ui


npm ERR! Linux 3.13.0-85-generic
npm ERR! argv "node" "/home/user/.meteor/packages/meteor-tool/.1.3.1.9bkup9++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/npm" "install" "--save" "material-ui"
npm ERR! node v0.10.43
npm ERR! npm  v2.14.22
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package react@15.0.1 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer react-addons-pure-render-mixin@15.0.1 wants react@^15.0.1
npm ERR! peerinvalid Peer react-dom@15.0.1 wants react@^15.0.1
npm ERR! peerinvalid Peer react-tap-event-plugin@0.2.2 wants react@^0.14.0
npm ERR! peerinvalid Peer material-ui@0.14.4 wants react@^0.14.0

npm ERR! Please include the following file with any support request:
npm ERR!     /home/user/meteor/app/npm-debug.log

1 个答案:

答案 0 :(得分:1)

我不确定我是否理解了您的问题,但我想您要问的是:"用户执行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 documentationhttp://cs.wellesley.edu/~mashups/pages/meteor6.html

中找到有关该内容的更多详细信息