I send this with postman in the body :
{ "username": "jeantille", "mail": "jeantille@gmail.com", "password": "motdepasse" }
I think that i have to send two request at different time but I can't. Can you help me please.
controllers/user.js
exports.signup = (req, res, next) => {
User.findOne({
attributes: ['mail'],
where: {
mail: req.body.mail
}
})
.then(userExist => {
if(!userExist) {
bcrypt.hash(req.body.password, 10)
.then(hash => {
const user = User.build({
username: req.body.username,
mail: req.body.mail,
password: hash,
admin: 0
});
user.save()
.then(() => res.status(201).json({ message: 'Votre compte a bien été créé !' }))
.catch(error => res.status(400).json({ error: '⚠ Oops, une erreur s\'est produite !' }));
})
.catch(error => res.status(500).json({ error: 'Une erreur s\'est produite lors de la création de votre compte' }));
} else {
return res.status(404).json({ error: 'Cet utilisateur existe déjà' })
}
})
.catch(error => res.status(500).json({ error: '⚠ Oops, une erreur s\'est produite !' }));
};