text: import passport from 'passport';
  import {Strategy as GoogleStrategy} from 'passport-google-oauth20';
  
  export function setup(User, config) {
    passport.use(new GoogleStrategy({
      clientID: config.google.clientID,
      clientSecret: config.google.clientSecret,
      callbackURL: config.google.callbackURL
    },
    function(accessToken, refreshToken, profile, done) {
      User.find({where:{'email': profile.emails[0].value}})
        .then(user => {
          if (user) {
            return done(null, user);
          }
  
          user = User.build({
            name: profile._json.displayName,
            email: profile.emails[0].value,
            theme:'default',
            role: 'user',
            username: profile.emails[0].value.split('@')[0],
            provider: 'google',
            google: profile._json
          });
          user.save()
            .then(user => done(null, user))
            .catch(err => done(err));
        })
        .catch(err => done(err));
    }));
  }
  