问题描述
我是 Node.js 的新手,也是 MongoDB 的新手。
我正在尝试使用 Google OAuth 2.0 和护照制作身份验证系统。
我不断收到此错误:
Error: User validation Failed: lastName: Path `lastName` is required.
你能帮我吗?我从 GitHub 获得了这段代码,我正在尝试修改它,但是这个错误并没有让我继续我的项目。
这是有问题的代码:
const mongoose = require('mongoose')
const User = require('../models/User')
module.exports = function (passport) {
passport.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID,clientSecret: process.env.GOOGLE_CLIENT_SECRET,callbackURL: '/auth/google/callback',},async (accesstoken,refreshToken,profile,done) => {
const newUser = {
googleId: profile.id,displayName: profile.displayName,firstName: profile.name.givenname,lastName: profile.name.familyName,image: profile.photos[0].value,}
try {
let user = await User.findOne({ googleId: profile.id })
if (user) {
done(null,user)
} else {
user = await User.create(newUser)
done(null,user)
}
} catch (err) {
console.error(err)
}
}
)
)
passport.serializeUser((user,done) => {
done(null,user.id)
})
passport.deserializeUser((id,done) => {
User.findById(id,(err,user) => done(err,user))
})
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)