i'm trying to hash the password inside the ueserRouter with hashSync to create a signup the error: data and salt are required if someone can help how can i declare data and salt in this function
the code below:
const userRouter = express.Router();
userRouter.post('/signup',expressAsyncHandler(async (req, res) => {
const newUSer = new User({
name: req.body.name,
email: req.body.email,
password: bcrypt.hashSync(req.body.password)
});
const user = await newUSer.save();
res.send({
_id: user._id,
name: user.name,
email: user.email,
isAdmin: user.isAdmin,
token: generateToken(user),
});
}) );
The problem that i was defining password as a number in userSchema
so I changed it to string.
Then I made this change in userRouter
:
password: bcrypt.hashSync(req.body.password, 10);
Instead of:
password: bcrypt.hashSync(req.body.password)