我正在尝试使用OAuth2 Passportjs策略使用Google Auth。我既无法检查数据库中的现有用户,也无法将新用户保存到数据库中。使用Google登录后,似乎我没有得到回复,或者我的查询有问题。
我尝试了async / await语法,我尝试了console.log应该由Google发回的配置文件对象,并且console.log没有显示。
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)
})
}
每次调用回调时,都会出现TypeError: Cannot read property 'query' of undefined
错误