简体   繁体   中英

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).

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. 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.

What could be going on here? Or how would I debug this? Suggestions appreciated.

ps If any additional information is needed, I can ammend.

You probably messed up oauth configuration either on the Meteor side or Google Developers Console side, so here is a quick recap.

Google Developers Console :

Under APIs & auth > Credentials, create a new Client ID in the OAuth section.

Choose Web Application and specify both correct redirect URIs and JavaScript origins :

REDIRECT URIS

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

JAVASCRIPT ORIGINS

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

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.

Then call Meteor.loginWithGoogle() in the click handler of your login form and it should work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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