1- const express = require ( 'express' ) ;
1+ const express = require ( "express" ) ;
2+ const { body } = require ( "express-validator/check" ) ;
23
34const router = express . Router ( ) ;
45
5- const authControllers = require ( '../controllers/auth.controllers' ) ;
6-
7- router . post ( '/register' , authControllers . postRegisterController ) ;
8-
9- router . post ( '/login' , authControllers . postLoginController ) ;
10-
11- router . post ( '/logout' , authControllers . postLogoutController ) ;
12-
13- router . get ( '/verify' , authControllers . getVerifyController ) ;
14-
15- router . post ( '/reset-password-request' , authControllers . postFPassReq ) ;
16-
17- router . post ( '/reset-password' , authControllers . postResetPassword ) ;
18-
19- module . exports = router ;
6+ const authControllers = require ( "../controllers/auth.controllers" ) ;
7+
8+ router . post (
9+ "/register" ,
10+ [
11+ body ( "email" ) . isEmail ( ) . withMessage ( "Email must be valid" ) ,
12+ body ( "password" )
13+ . isLength ( { min : 6 } )
14+ . withMessage ( "Password must be at least 6 characters long" )
15+ . contains ( "[0-9]" )
16+ . withMessage ( "Password must contain a number" )
17+ . contains ( "[a-z]" )
18+ . withMessage ( "Password must contain a lowercase letter" )
19+ . contains ( "[A-Z]" )
20+ . withMessage ( "Password must contain an uppercase letter" )
21+ . contains ( "[@$!%*#?&]" )
22+ . withMessage ( "Password must contain a special character" ) ,
23+ body ( "confirmPassword" )
24+ . matches ( req . body . password )
25+ . withMessage ( "Passwords must match" ) ,
26+ ] ,
27+ authControllers . postRegisterController
28+ ) ;
29+
30+ router . post (
31+ "/login" ,
32+ [
33+ body ( "email" ) . isEmail ( ) . withMessage ( "Email must be valid" ) ,
34+ body ( "password" )
35+ . isLength ( { min : 6 } )
36+ . withMessage ( "Password must be at least 6 characters long" ) ,
37+ ] ,
38+ authControllers . postLoginController
39+ ) ;
40+
41+ router . post ( "/logout" , authControllers . postLogoutController ) ;
42+
43+ router . get ( "/verify" , [ ] , authControllers . getVerifyController ) ;
44+
45+ router . post ( "/reset-password-request" , [ ] , authControllers . postFPassReq ) ;
46+
47+ router . post ( "/reset-password" , [ ] , authControllers . postResetPassword ) ;
48+
49+ module . exports = router ;
0 commit comments