DEV Community

Hadi
Hadi

Posted on

Signing in with google

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 th 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);
    }
));
Enter fullscreen mode Exit fullscreen mode

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('/')
  });
Enter fullscreen mode Exit fullscreen mode

If I put : 'session:true' an error occurs: The result:

[nodemon] app crashed - waiting for file changes before starting...
Enter fullscreen mode Exit fullscreen mode

I cann'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
when set session: false, no error occurs but without signing in.

Top comments (2)

Collapse
 
jainsakshi profile image
Sakshi J

thanks for this blog!

Collapse
 
hadi255 profile image
Hadi

Thank you!