【问题标题】:Can anyone help me with this error related to passportjs谁能帮我解决与passportjs相关的错误
【发布时间】:2020-05-16 23:07:06
【问题描述】:
ReferenceError: User is not defined
    at Strategy._verify (C:\Projects\config\passport.js:9:5)
    at Strategy.authenticate (C:\Projects\node_modules\passport-local\lib\strategy.js:90:12)
    at attempt (C:\Projects\node_modules\passport\lib\middleware\authenticate.js:366:16)
    at authenticate (C:\Projects\node_modules\passport\lib\middleware\authenticate.js:367:7)
    at Layer.handle [as handle_request] (C:\Projects\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Projects\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Projects\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Projects\node_modules\express\lib\router\layer.js:95:5)
    at C:\Projects\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Projects\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Projects\node_modules\express\lib\router\index.js:275:10)
    at SessionStrategy.strategy.pass (C:\Projects\node_modules\passport\lib\middleware\authenticate.js:343:9)
    at SessionStrategy.authenticate (C:\Projects\node_modules\passport\lib\strategies\session.js:75:10)
    at attempt (C:\Projects\node_modules\passport\lib\middleware\authenticate.js:366:16)
    at authenticate (C:\Projects\node_modules\passport\lib\middleware\authenticate.js:367:7)
    at Layer.handle [as handle_request] (C:\Projects\node_modules\express\lib\router\layer.js:95:5)

【问题讨论】:

  • 你在做什么?
  • 你能发布更多的代码sn-p吗?这很容易帮助你。
  • 我正在尝试使用 bcryptjs 对密码进行哈希处理并保存在数据库(MongoDB)中。我无法进行身份验证。我正在使用 passportjs 进行身份验证。

标签: node.js express passport.js bcrypt


【解决方案1】:

您必须在 models.js 中创建一个用户架构并将其导出到您的 passport 配置文件

【讨论】:

  • 在不知道他实际在做什么或与该用户定义的情况下,你怎么能这么说。
  • 用户未定义,因此要么他没有创建它,要么他不需要它
  • 请将您的 passportjs 配置代码也放在这里用户模式,以便我可以定义错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-27
  • 2019-09-26
相关资源
最近更新 更多