diff --git a/api/routes/users_routes.js b/api/routes/users_routes.js index 3922be6d351d9a8b88f0a6e1b02eb11a87bfbc62..edde650950c3cca9e06aa7d9d167ef80f9296c0a 100644 --- a/api/routes/users_routes.js +++ b/api/routes/users_routes.js @@ -16,7 +16,7 @@ const userSchema = Joi.object({ }); // Créer un nouvel utilisateur -router.post('/', validator.body(userSchema), async function(req, res){ +router.post('/', validator.body(userSchema), async function(req, res, next){ if (req.body.confirm !== req.body.password){ return res.status(400).json({ @@ -31,7 +31,7 @@ router.post('/', validator.body(userSchema), async function(req, res){ if(user){ return res.status(409).json({ error: 'Username already exists.' - }) + }); } } catch(err) { return next(err); @@ -50,7 +50,7 @@ router.post('/', validator.body(userSchema), async function(req, res){ } res.json(newUser); -}) +}); const userSchemaLogin = Joi.object({ username: Joi.string().required().trim().min(1), @@ -70,7 +70,7 @@ router.post('/login', validator.body(userSchemaLogin), async function(req, res, if (!user){ return res.status(401).json({ error: 'Fail to authenticate with given credentials.' - }) + }); } const password = crypto.createHash('md5').update(req.body.password).digest("hex"); @@ -91,7 +91,7 @@ router.post('/login', validator.body(userSchemaLogin), async function(req, res, } ); return res.json({token, user: {username: user.username, id: user._id}}); -}) +}); //Récupérer la liste des utilisateurs router.get('/', async function (req, res, next){ @@ -109,6 +109,6 @@ router.get('/', async function (req, res, next){ } return res.json(users); -}) +}); export default router;