Error: data and salt arguments required at Object.hash (D:\social-media\rest-api\node_modules\bcrypt\bcrypt.js:137:17) at D:\social-media\rest-api\node_modules\bcrypt\promises.js:29:12 at new Promise () at Object.module.exports.promise (D:\social-media\rest-api\node_modules\bcrypt\promises.js:20:12) at Object.hash (D:\social-media\rest-api\node_modules\bcrypt\bcrypt.js:133:25) at D:\social-media\rest-api\routes\auth.js:8:45
const router = require("express").Router();
const User = require("../models/Users");
const bcrypt = require("bcrypt");
router.post("/register", async (req, res) => {
try {
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(req.body.password, salt);
const newUser = new User({
username: req.body.username,
email: req.body.email,
password: hashedPassword
});
const user = await newUser.save();
res.status(200).json(user);
} catch (err) {
console.log(err)
}
});
router.get("/register", (req, res) => {
res.send("runing");
});
module.exports = router;
How about only use const in bcypt.hash
const hashedPassword = await bcrypt.hash(req.body.password, 10)