-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
34 lines (30 loc) · 920 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// User routes / Auth
// host + /api/auth
const { Router } = require('express');
const router = Router();
const { check } = require('express-validator');
const { createUser, login, renewToken } = require('../controllers/auth');
const { validateFields } = require('../middlewares/fieldsValidator');
const { validateJWT } = require('../middlewares/jwtValidator');
router.post(
'/new',
[
//middlewares
check('name', 'Name is mandatory').not().isEmpty(),
check('email', 'Email is not valid').isEmail(),
check('password', 'Password must have at least 5 characters').isLength({ min: 5 }),
validateFields,
],
createUser
);
router.post(
'/login',
[
check('email', 'Not valid email').isEmail(),
check('password', 'Password length must be greater that 5').isLength({ min: 5 }),
validateFields,
],
login
);
router.get('/renew', validateJWT, renewToken);
module.exports = router;