MrFullStack
MrFullStack

Reputation: 502

Passport.authenticate loops forever

I am using Passport.js to connect my Node application to the Google+ API using a GoogleStrategy. I call the auth/api route from my frontend (localhost:3000) to my server (localhost:5150). My code gets to the route successfully and calls the passport.authenticate("google", { scope: ["email"] }) method but no action is performed. My frontend just waits endlessly for the Google callback but it never comes.

Why would this be happening?

My code:

export const authenticateUsingGoogle = (req, res) => {
  console.log(`authenticating using google`);
    passport.authenticate("google", { scope: ["email", "openid", "profile "] });
  console.log(`authenticated using google`);
};

I have seen two similar questions being asked on Stackoverflow but they have no answers:

passport.authenticate() loads forever

Passport.authenticate() gets stucks

Upvotes: 1

Views: 627

Answers (1)

oznakn
oznakn

Reputation: 90

passport.authenticate method returns a middleware for express. You need to use it as an argument for your express router.

Example:

app.post('/login/password',
  passport.authenticate("google", { scope: ["email", "openid", "profile "] }),
  function(req, res) {
    // Your actual code.
  });

You can find more information here.

Upvotes: 1

Related Questions