Bcrypt error: illegal arguments String unidentified

后端 未结 8 1997
误落风尘
误落风尘 2021-01-17 10:49

here is my complete code

var express = require(\'express\'),
    app = express(),
    mongoose = require(\'mongoose\'),
    bodyParser = require(\'body-parse         


        
8条回答
  •  爱一瞬间的悲伤
    2021-01-17 11:20

    In your User Schema, you are setting select to false for the password field. This means that anytime you look for a user in the schema as you're trying to do in the login request, you won't get the value of the password field or any other field that has select false defined in the schema.

    What you need to do is to specify you need the password when the user is found:

    app.post('/login', function(req, res){
      userModel.findOne({username: req.body.username}, 'password', function(err, user){
       // continue
    }
    
    

    This will return only the _id and the password from the DB. If you want to return other fields, you'd have to add them in:

    app.post('/login', function(req, res){
      userModel.findOne({username: req.body.username}, 'password firstName lastName email', function(err, user){
       // continue
    }
    
    

提交回复
热议问题