Skip to content

Commit

Permalink
[FIX]: user register
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaryoshida committed Nov 22, 2023
1 parent a6a7746 commit 3d827cc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions backend/controllers/UserControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ const bcrypt = require('bcrypt');
const { sign } = require('jsonwebtoken');
const { createToken, validateToken } = require('./middlewares/Auth');

exports.userRegister = async(req, res) => {
exports.userRegister = async (req, res) => {
const { email, password } = req.body;
const existingUser = await Users.findOne({ where: { email: email } });

if (existingUser) {
return res.status(400).json({ error: 'E-mail já cadastrado!' });
}

bcrypt.hash(password, 15).then((hash) => {
Users.create({
email: email,
password: hash,
}).then(() =>{
})
.then(() => {
res.json('Solicitação bem sucedida!');
}).catch((err) => {
if(err){
res.status(400).json({error: err});
})
.catch((err) => {
if (err) {
res.status(400).json({ error: err });
}
});
});
};


exports.userLogin = async(req, res) => {
const { email, password } = req.body;
const user = await Users.findOne({where: {email: email}});
Expand Down

0 comments on commit 3d827cc

Please sign in to comment.