сервер не может принять данные в json
const dataToSend = {"_id":"lfg","email": "[email protected]", "password": "101010"};
fetch ('http://localhost:5000/auth/registration',{
method:'POST',
body: JSON.stringify(dataToSend)
}).then((response) => response.json())
На сервер приходят следующие данные:
{}
Код приема данных на сервере:
async registration(req,res)
{
console.log(req.body)
try
{
const {_id,email,password} = req.body
const candidate = await User.findOne({_id})
if(candidate){
return res.status(400).json({message:"Такой юзернейм занят"})
}
const hash_crypt = await bcryptjs.hashSync(password, 7);
const user = new User({_id,email,password:hash_crypt})
await user.save()
return res.json({message:"Успешная регистрация!"})
}
catch(e)
{
console.log(e)
res.status(400).json({message:"Server error! "})
}
}
Если отправлять через postman, то все работает.