title: req.user not available in Google Passport Strategy
body: <p>I have an express app which manages authentication via Passport, initially with a local strategy.  To this I have just added Google sign in / account creation and almost everything works as per the docs.</p>
  
  <p>The problem I have is that a user can create an account using the Google Strategy but I cannot quite get it so that an authenticated user (via the local strategy) can simply add additional Google details to their account so that they can use either the local or Google strategy.</p>
  
  <p>In 'index.js' where I define my routes I define <code>const passportGoogle = require('../handlers/google');</code> which has the details of my Google Strategy.</p>
  
  <p>Further down in <code>index.js</code> I have my <code>authenticate</code> and <code>authorise</code> routes:</p>
  
  <pre><code>/* GOOGLE ROUTES FOR AUTHENTICATION*/
  
  router.get('/google',
      passportGoogle.authenticate('google', 
      { scope: ['profile', 'email'] }));
  
  router.get('/google/callback', 
      passportGoogle.authenticate('google', 
      {
          failureRedirect: '/',
          failureFlash: 'Failed Login!',
          successRedirect: '/account',
          successFlash: 'You are logged in!'
  
      }
  ));
  
  /* GOOGLE ROUTES FOR AUTHORISATION - IE A USER IS ALREADY LOGGED IN AND WANTS TO CONNECT THEIR GOOGLE ACCOUNT*/
  
  // send to google to do the authentication
  router.get('/connect/google', 
      passportGoogle.authorize('google', 
      { scope : ['profile', 'email'] }
  ));
  
  // the callback after google has authorized the user
  router.get('/connect/google/callback',
      passportGoogle.authorize('google', {
          successRedirect : '/profile',
          failureRedirect : '/'
      })
  );
  </code></pre>
  
  <p>As above my Google strategy is defined in <code>google.js</code>:</p>
  
  <pre><code>var passport = require('passport');
  var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
  var User = require('../models/User');
  passport.use(new GoogleStrategy({
      clientID: process.env.GOOGLE_CLIENTID,
      clientSecret: process.env.GOOGLE_CLIENTSECRET,
      callbackURL: "http://127.0.0.1:7777/google/callback"
    },
    // google will send back the token and profile
  function(req, token, refreshToken, profile, done) {
  // console.log('here is res.locals.user'+ res.locals.user);
          console.log('here is req.user'+ req.user);
      // asynchronous
      process.nextTick(function() {
  
          // check if the user is already logged in
          if (!req.user) {
              console.log('THERE IS NO REQ.USR');
              // find the user in the database based on their facebook id
              User.findOne({ 'google.id': profile.id }, function(err, user) {
  
                  // if there is an error, stop everything and return that
                  // ie an error connecting to the database
                  if (err)
                      return done(err);
  
                  // if the user is found, then log them in
                  if (user) {
                      return done(null, user); // user found, return that user
                  } else {
                      // if there is no user found with that google id, create them
                      var newUser            = new User();
  
                      // set all of the facebook information in our user model
                      newUser.google.id = profile.id;
                      newUser.google.token = token;
                      newUser.name = profile.displayName;
                      newUser.email = profile.emails[0].value;
  
                      // save our user to the database
                      newUser.save(function(err) {
                          if (err)
                              throw err;
  
                          // if successful, return the new user
                          return done(null, newUser);
                      });
                  }
  
              });
  
          } else {
              const user = User.findOneAndUpdate(
                  { _id: req.user._id },
                  { $set: {"user.google.id":profile.id, 
                          "user.google.token":accessToken, 
                          "user.google.name":profile.displayName, 
                          "user.google.email":profile.emails[0].value
                      }
                  },   
                  { new: true, runValidators: true, context: 'query' }
              )
              .exec();
              return done(null, user);
              req.flash('success', 'Google details have been added to your account'); 
              res.redirect(`back`); 
          }
      });
  }));
  
  module.exports = passport;
  </code></pre>
  
  <p>However when a user is signed in and follows the link to <code>/connect/google</code> a new user is always created rather than their details updated.  My logging shows that <code>if (!req.user)</code> condition in the Google stratgy is always firing but I'm not sure why that is since the user is definitely logged in.</p>
  
  <p>Any help much appreciated!</p>