11import OTPStore from "#models/otpStore" ;
2- import util , { logger } from "#util" ;
2+ import util , { logger } from "#util" ;
33import { authenticateUser , userExists , updatePassword } from "#services/user" ;
44
55async function login ( req , res ) {
@@ -16,7 +16,7 @@ async function login(req, res) {
1616 userDetails . token = token ;
1717 res . json ( { res : "welcome" , user : userDetails } ) ;
1818 } catch ( error ) {
19- logger . error ( "Error while login" , error )
19+ logger . error ( "Error while login" , error ) ;
2020 if ( error . name === "UserDoesNotExist" ) {
2121 res . status ( 403 ) ;
2222 res . json ( { err : "Incorrect ID password" } ) ;
@@ -35,7 +35,7 @@ async function sendOTP(req, res) {
3535 const { uid, emailId } = req . body ;
3636 if ( await userExists ( uid , emailId ) ) {
3737 const otp = Math . floor ( 1000 + Math . random ( ) * 9000 ) ;
38- await OTPStore . update ( { uid : uid } , { otp : otp } ) ;
38+ await OTPStore . update ( { uid } , { otp } ) ;
3939 util . sendOTP ( emailId , otp ) ;
4040 res . json ( { res : "otp sent to emailID" } ) ;
4141 } else {
@@ -45,13 +45,13 @@ async function sendOTP(req, res) {
4545
4646async function resetPassword ( req , res ) {
4747 const { uid, otp, password } = req . body ;
48- const storedOtp = await OTPStore . read ( { uid : uid } ) ;
48+ const storedOtp = await OTPStore . read ( { uid } ) ;
4949 if ( storedOtp [ 0 ] . otp === `${ otp } ` ) {
5050 try {
5151 await updatePassword ( uid , password ) ;
5252 res . json ( { res : "successfully updated password" } ) ;
5353 } catch ( error ) {
54- logger . log ( "Error while updating" , error )
54+ logger . log ( "Error while updating" , error ) ;
5555 res . status ( 500 ) ;
5656 if ( error . name === "UpdateError" ) res . json ( { err : "Something went wrong while updating password" } ) ;
5757 else res . json ( { err : "something went wrong" } ) ;
@@ -60,7 +60,6 @@ async function resetPassword(req, res) {
6060 res . json ( { err : "incorrect otp" } ) ;
6161 }
6262}
63-
6463
6564export default {
6665 validateUser, sendOTP, resetPassword, login,
0 commit comments