我从heroku中收到一个奇怪的错误,指出:TypeError:OAuth2Strategy需要一个clientID选项。
我解决了有关脚本任务的一个错误。我尝试删除文件并重建整个应用程序
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const mongoose = require('mongoose');
const keys = require('../config/keys');
const googleClientID = keys.googleClientID
const googleClientSecret = keys.googleClientSecret
const User = mongoose.model('users');
//Takes user model and passes it into a cookie
//Use Mongo autogenerated ID
passport.serializeUser((user, done)=>{
done(null, user.id)
});
passport.deserializeUser((id, done)=>{
User.findById(id)
.then((user)=>{
done(null, user);
})
});
// Creates a new instance of google strategy
// Tells Google how to authenticate Google strategies
passport.use(new GoogleStrategy({
clientID: googleClientID,
clientSecret: googleClientSecret,
callbackURL: '/auth/google/callback',
proxy: true
},
//Whenever we reach out to our database it is an asynchronous
async (accessToken, refreshToken, profile, done ) =>{
const existingUser = await User.findOne({googleID: profile.id})
if(existingUser){
console.log(profile.emails[0].value)
done(null, existingUser)
}
const user = await new User({googleID: profile.id, email: profile.emails[0].value, name: profile.displayName}).save()
done(null, user);
}));