Cannot sign in with Google

62 Views Asked by At

I use node.js in my project and try to make the site can be signed in with google, but after choosing the email(account), it redirect to the right page successfully but without signing in.

passport.js:

passport.use(new GoogleStrategy({
    clientID: process.env.GOOGLE_CLIENT_ID,
    clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    callbackURL: "http://localhost:4000/auth/google/callback",
    passReqToCallback: true
},
    function (request, accessToken, refreshToken, profile, done) {

        done(null, profile);
    }
));

index.js:

router.get('/auth/google',
  passport.authenticate('google', {
    scope: ['email', 'profile']
  }
  ));

router.get('/auth/google/callback',
  passport.authenticate('google', { 
    session: false,
    failureRedirect: 'signup' }),
  (req, res) => {
    res.redirect('/')
  });

If I use 'session:true', an error happens:

[nodemon] app crashed - waiting for file changes before starting...

I can't know what is happening, the redirect is successful to the page http://localhost:4000/ but it doesn't open because [nodemon] app crashed, and without signing in.

0

There are 0 best solutions below