Bcrypt error: illegal arguments String unidentified

后端 未结 8 1995
误落风尘
误落风尘 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:22

    Do like this:

    UserSchema.pre('save', async function (next) {
      const hash = await bcrypt.hash(this.password, 10);
    
      this.password = hash;
      next()
    })
    

提交回复
热议问题