ValidatorError:需要路径`lastName`

问题描述

我是 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...