File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,10 +115,16 @@ app.use(hpp());
115115app . use ( cors ( ) ) ;
116116
117117// Enforce secret presence in production; provide safe fallback in dev/test
118- if ( process . env . NODE_ENV === "production" && ( ! process . env . SESSION_SECRET || ! process . env . JWT_SECRET ) ) {
119- throw new Error ( "FATAL SECURITY ERROR: SESSION_SECRET and JWT_SECRET must be defined in production mode." ) ;
118+ if (
119+ process . env . NODE_ENV === "production" &&
120+ ( ! process . env . SESSION_SECRET || ! process . env . JWT_SECRET )
121+ ) {
122+ throw new Error (
123+ "FATAL SECURITY ERROR: SESSION_SECRET and JWT_SECRET must be defined in production mode." ,
124+ ) ;
120125}
121- const sessionSecret = process . env . SESSION_SECRET || "dev_session_secret_fallback_key_32_chars" ;
126+ const sessionSecret =
127+ process . env . SESSION_SECRET || "dev_session_secret_fallback_key_32_chars" ;
122128
123129// Set up session middleware
124130app . use (
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ const forgotPasswordLimiter = expressRateLimit({
2121 validate : { trustProxy : false } ,
2222 message : {
2323 success : false ,
24- error : "Too many password reset requests from this IP, please try again after 15 minutes" ,
24+ error :
25+ "Too many password reset requests from this IP, please try again after 15 minutes" ,
2526 } ,
2627} ) ;
2728
@@ -35,6 +36,8 @@ const {
3536 loginSchema,
3637 resetPasswordSchema,
3738 forgotPasswordSchema,
39+ updateDetailsSchema,
40+ updatePasswordSchema,
3841 } ,
3942} = require ( "../utils/validators" ) ;
4043
@@ -44,8 +47,18 @@ router.get("/logout", logout);
4447router . get ( "/csrf-token" , getCsrfToken ) ;
4548router . get ( "/me" , protect , getMe ) ;
4649
47- router . put ( "/updatedetails" , protect , updateDetails ) ;
48- router . put ( "/updatepassword" , protect , updatePassword ) ;
50+ router . put (
51+ "/updatedetails" ,
52+ protect ,
53+ validate ( updateDetailsSchema ) ,
54+ updateDetails ,
55+ ) ;
56+ router . put (
57+ "/updatepassword" ,
58+ protect ,
59+ validate ( updatePasswordSchema ) ,
60+ updatePassword ,
61+ ) ;
4962
5063router . post (
5164 "/forgotpassword" ,
Original file line number Diff line number Diff line change @@ -20,9 +20,21 @@ const forgotPasswordSchema = Joi.object({
2020 email : Joi . string ( ) . email ( ) . required ( ) ,
2121} ) . unknown ( true ) ;
2222
23+ const updateDetailsSchema = Joi . object ( {
24+ name : Joi . string ( ) . optional ( ) ,
25+ email : Joi . string ( ) . email ( ) . optional ( ) ,
26+ } ) . unknown ( true ) ;
27+
28+ const updatePasswordSchema = Joi . object ( {
29+ currentPassword : Joi . string ( ) . required ( ) ,
30+ newPassword : Joi . string ( ) . min ( 6 ) . required ( ) ,
31+ } ) . unknown ( true ) ;
32+
2333module . exports = {
2434 registerSchema,
2535 loginSchema,
2636 resetPasswordSchema,
2737 forgotPasswordSchema,
38+ updateDetailsSchema,
39+ updatePasswordSchema,
2840} ;
You can’t perform that action at this time.
0 commit comments