简体   繁体   English

(显然)成功登录后,Meteor.user为null

[英]Meteor.user is null after (apparently) successful login

I have a simple Meteor js app that allows you to create a user account and log in, or to log in with your existing Google account via oauth (thanks to the accounts-google package). 我有一个简单的Meteor js应用程序,它允许您创建用户帐户并登录,或者通过oauth(由于accounts-google软件包)使用现有的Google帐户登录。

When using the app, I enter my username and password, everything works fine. 使用该应用程序时,我输入了用户名和密码,一切正常。 However, when I click "Sign in with Google", the google oauth pop-up asks me to select which google account I want to use for this login. 但是,当我单击“使用Google登录”时,google oauth弹出窗口要求我选择我要用于该登录的Google帐户。 I select the account, the pop up waits a second, closes, and then nothing happens. 我选择了帐户,弹出窗口等待一秒钟,然后关闭,然后什么都没有发生。 No pop-ups being blocked, no "failed login" messages. 没有弹出窗口被阻止,没有“登录失败”消息。 It's as if nothing happened at all. 好像什么都没有发生。

I'm certain that the user is never being defined when I use oauth login because Meteor.user() gives me null in the JS console. 我确定使用oauth登录时永远不会定义用户,因为Meteor.user()在JS控制台中为我提供了null

What could be going on here? 这可能是怎么回事? Or how would I debug this? 或者我该如何调试呢? Suggestions appreciated. 建议表示赞赏。

ps If any additional information is needed, I can ammend. ps如果需要任何其他信息,我可以补充。

You probably messed up oauth configuration either on the Meteor side or Google Developers Console side, so here is a quick recap. 您可能在Meteor端或Google Developers Console端弄乱了oauth配置,因此这里有个简短的回顾。

Google Developers Console : Google Developers Console:

Under APIs & auth > Credentials, create a new Client ID in the OAuth section. 在“ API和身份验证>凭据”下,在OAuth部分中创建一个新的客户端ID。

Choose Web Application and specify both correct redirect URIs and JavaScript origins : 选择Web应用程序,并指定正确的重定向URI和JavaScript来源:

REDIRECT URIS 重定向尿RIS

http://localhost:3000/_oauth/google?close
http://your-production-domain.com/_oauth/google?close

JAVASCRIPT ORIGINS JAVASCRIPT起源

http://localhost:3000
http://your-production-domain.com

Meteor configuration : 流星配置:

Be sure to add these packages : 确保添加以下软件包:

meteor add accounts-google
meteor add service-configuration

In server/config.js, add these lines from http://docs.meteor.com/#meteor_loginwithexternalservice 在server / config.js中,从http://docs.meteor.com/#meteor_loginwithexternalservice添加这些行

ServiceConfiguration.configurations.remove({
  service: "google"
});
ServiceConfiguration.configurations.insert({
  service: "google",
  clientId: "????????????????.apps.googleusercontent.com",
  secret: "????????????????"
});

The clientId and secret fields should be set to those in the Google Developers Console. 应将clientId和secret字段设置为Google Developers Console中的字段。

Then call Meteor.loginWithGoogle() in the click handler of your login form and it should work as expected. 然后在您的登录表单的点击处理程序中调用Meteor.loginWithGoogle() ,它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM