I am trying to make use of Google Auth using OAuth2 passportjs strategy. I can neither check for existing user in the database, nor save a new one into the database. After logging in with Google, it seems I'm either not getting a response back or there is something wrong with my query.
I've tried async/await syntax, I've tried to console.log the profile object that should be sent back by Google and the console.log does not show up.
passport.use (
new GoogleStrategy (
{
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: '/auth/google/callback',
},
async (accessToken, refreshToken, profile, done) => {
const existingUser = await knex('users').where({googleId: profile.id}).returning('*').then(data =>{
return data;
})
const userParams = {googleId: profile.id}
if(existingUser){
done(null, existingUser)
} else {
knex ('users').insert(userParams).returning("*").then(data => {
res.send(data)
})
}
Every time the callback is called, I get TypeError: Cannot read property 'query' of undefined
error