所以在我的注册函数中,当我在没有散列的情况下调用它时它工作得很好但是当我尝试对密码进行散列时它不起作用
任何人都可以帮助我吗?
当我删除
const hashedpassword = await bcrypt.hash(password, 10);
行代码正常工作
我不断收到此错误:ValidationError [SequelizeValidationError]: notNull Violation: User.password cannot be null
const express = require('express');
const User = require('../models/User');
const jwt = require("jsonwebtoken");
const bcrypt = require('bcryptjs');
const router = express.Router();
router.post('/register', async (req, res) => {
console.log('im here server');
const{fullName, email,password} = req.body;
const alreadyExistsuser = await User.findOne({where : { email }})
.catch((err) =>
console.log("error :" ,err));
if (alreadyExistsuser) {
return res.json({ message: 'Email already exists' });}
const hashedpassword = await bcrypt.hash(password, 10);
const newUser = new User({ fullName, email, hashedpassword });
const savedUser = await newUser.save().catch((err) => {
console.log( "error" ,err)
res.json({ error: 'cannot register',err });
});
if(savedUser){
const jwtToken = jwt.sign( { id: savedUser.id, email: savedUser.email }, process.env.JWT_SECRET );
const userInfo ={ fullName,email}
res.json({ message: 'User registered successfully'
,token: jwtToken,userInfo
});}
});
module.exports = router;