@@ -97,10 +97,22 @@ const verifyToken = async (req, res) => {
9797 }
9898} ;
9999
100- async function ResetPasswordByEmail ( req , resp ) {
101- const VITE_CLIENT_PORT = process . env . VITE_CLIENT_PORT || "https://bitbox-in.netlify.app" ;
100+ async function ResetPasswordByEmail ( req , res ) {
102101
102+ const VITE_CLIENT_PORT = process . env . VITE_CLIENT_PORT || "https://bitbox-in.netlify.app" ;
103103 const { email } = req . body ;
104+
105+ // Check if email is provided
106+ if ( ! email ) {
107+ return res . status ( 400 ) . json ( { error : 'Email is required' } ) ;
108+ }
109+
110+ const user = await User . findOne ( { email } ) ;
111+
112+ if ( ! user ) {
113+ return res . status ( 404 ) . json ( { error : 'User does not exist' } ) ;
114+ }
115+
104116 const transporter = nodemailer . createTransport ( {
105117 service : "gmail" ,
106118 auth : {
@@ -112,24 +124,23 @@ async function ResetPasswordByEmail(req, resp) {
112124 const mailOptions = {
113125 from : process . env . EMAIL_USER ,
114126 to : email ,
115- subject : "Reset Your password on BitBox" ,
127+ subject : "Reset Your Password on BitBox" ,
116128 html : `
117- <p>Reset your password using the link below:</p>
118- <a href="${ VITE_CLIENT_PORT } /reset-password"><button>Click here</button></a> to reset your password
119- ` ,
129+ <p>Reset your password using the link below:</p>
130+ <a href="${ VITE_CLIENT_PORT } /reset-password"><button>Click here</button></a> to reset your password
131+ ` ,
120132 } ;
121133
122134 transporter . sendMail ( mailOptions , ( error , info ) => {
123135 if ( error ) {
124- console . log ( "Error sending email: " + error ) ;
125- resp . status ( 500 ) . send ( "Error sending email" ) ;
136+ return res . status ( 500 ) . json ( { error : "Error sending email" } ) ;
126137 } else {
127- console . log ( "Email sent: " + info . response ) ;
128- resp . status ( 200 ) . send ( { message : "email sent successfully" } ) ;
138+ return res . status ( 200 ) . json ( { message : "Email sent successfully" } ) ;
129139 }
130140 } ) ;
131141}
132142
143+
133144const forgetpassword = async ( req , res ) => {
134145 try {
135146 const { email, password } = req . body ;
0 commit comments