title: Google Authentication using Sails.js
body: <p>When I have tried to implement Google authentication in my site, using sails JavaScript, and MySQL getting error. I have using passport and passport-Google-auth Strategy. Problem is not getting data to my site from Google</p>
  
  <p>My Express Config(express.js) file is like below,</p>
  
  <pre><code>var passport = require('passport')
      , GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
  
  
  var verifyHandler = function(token, tokenSecret, profile, done) {
    process.nextTick(function() {
      console.log(profile)
      User.findOne({uid: profile.id}, function(err, user) {
        if (user) {
          return done(null, user);
        } else {
  
          var data = {
            provider: profile.provider,
            uid: profile.id,
            name: profile.displayName
          };
  
          if (profile.emails &amp;&amp; profile.emails[0] &amp;&amp; profile.emails[0].value) {
            data.email = profile.emails[0].value;
          }
          if (profile.name &amp;&amp; profile.name.givenName) {
            data.firstname = profile.name.givenName;
          }
          if (profile.name &amp;&amp; profile.name.familyName) {
            data.lastname = profile.name.familyName;
          }
  
          User.create(data, function(err, user) {
            return done(err, user);
          });
        }
      });
    });
  };
  
  passport.serializeUser(function(user, done) {
    console.log(user)
    done(null, user.uid);
  });
  
  passport.deserializeUser(function(uid, done) {
    User.findOne({uid: uid}, function(err, user) {
      done(err, user);
    });
  });
  
  module.exports.http = {
  
    customMiddleware: function(app) {
      passport.use(new GoogleStrategy({
        clientID: 'Client Id here',
        clientSecret: 'Secret key here',
        callbackURL: 'http://localhost:1337/auth/google/callback'
      }, verifyHandler));
  
  
  
      app.use(passport.initialize());
      app.use(passport.session());
    }
  
  };
  
  module.exports.cache = {
  
    // The number of seconds to cache files being served from disk
    // (only works in production mode)
    maxAge: 31557600000
  };
  module.exports.userlogin = {  
    userModel: 'user'  
  };
  </code></pre>
  
  <p>And My Auth Controller I have added code like below,</p>
  
  <pre><code>google: function(req, res) {
    passport.authenticate('google',{ 
      failureRedirect: '/login', scope: ['profile', 'email']  
    }, function(err, user) {
        req.logIn(user, function(err) {
        if (err) {
          console.log(err);
          res.view('500');
          return;
        }
        res.redirect('/');
          return;
        });
    })(req, res);
  },
  </code></pre>