@@ -5,7 +5,7 @@ const otpStore = {};
55
66async function login ( req , res ) {
77 const { id, password } = req . body ;
8- try {
8+ try {
99 const userValidated = await authenticateUser ( id , password ) ;
1010 const userDetails = {
1111 uid : userValidated . uid ,
@@ -16,15 +16,13 @@ async function login(req, res) {
1616 const token = util . genrateToken ( userDetails ) ;
1717 userDetails . token = token ;
1818 res . json ( { res : "welcome" , user : userDetails } ) ;
19- }
20- catch ( error ) {
21- if ( error . name === "UserDoesNotExist" ) {
19+ } catch ( error ) {
20+ if ( error . name === "UserDoesNotExist" ) {
2221 res . status ( 403 ) ;
23- res . json ( { err : "Incorrect ID password" } )
24- }
25- else {
22+ res . json ( { err : "Incorrect ID password" } ) ;
23+ } else {
2624 res . status ( 500 ) ;
27- res . json ( { err : "Something is wrong on our side. Try again" } ) ;
25+ res . json ( { err : "Something is wrong on our side. Try again" } ) ;
2826 }
2927 }
3028}
@@ -48,22 +46,19 @@ async function sendOTP(req, res) {
4846async function resetPassword ( req , res ) {
4947 const { uid, otp, password } = req . body ;
5048 if ( otpStore [ uid ] === otp ) {
51- try {
49+ try {
5250 await updatePassword ( uid , password ) ;
5351 res . json ( { res : "successfully updated password" } ) ;
54- }
55- catch ( error ) {
52+ } catch ( error ) {
5653 res . status ( 500 ) ;
57- if ( error . name === "UpdateError" )
58- res . json ( { err : "Something went wrong while updating password" } ) ;
59- else
60- res . json ( { err : "something went wrong" } ) ;
54+ if ( error . name === "UpdateError" ) res . json ( { err : "Something went wrong while updating password" } ) ;
55+ else res . json ( { err : "something went wrong" } ) ;
6156 }
6257 } else {
6358 res . json ( { err : "incorrect otp" } ) ;
6459 }
6560}
6661
6762export default {
68- validateUser, sendOTP, resetPassword, login
63+ validateUser, sendOTP, resetPassword, login,
6964} ;
0 commit comments