Skip to content

Commit

Permalink
fix: verifyController
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharbansal22 committed Apr 8, 2024
1 parent b6e20ec commit 846edff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions controllers/userAuth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports.verifyOtp = async (req, res, next) => {
const currentDateTime = new Date();

const user = await User.findOne({ email });
const userCredentials = await UserCredentials.findOne({ email });
if (!user) {
next({ status: 400, message: USER_NOT_FOUND_ERR });
console.log("user not found");
Expand All @@ -48,10 +49,13 @@ exports.verifyOtp = async (req, res, next) => {
}
if (otp.expiresAt < currentDateTime) {
next({ status: 400, message: OTP_EXPIRED_ERR });
await user.deleteOne();
await userCredentials.deleteOne();
return;
}

const token = createJwtToken({ userId: user._id });
await userCredentials.updateOne({ is_verified: true });

res.status(201).json({
type: "success",
Expand Down
2 changes: 1 addition & 1 deletion errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ exports.INCORRECT_CRED_ERR =
exports.EMAIL_NOT_FOUND_ERR = "Email not found";

exports.ADMIN_NOT_FOUND = "Admin not found";
exports.OTP_EXPIRED_ERR = "OTP has expired";
exports.OTP_EXPIRED_ERR = "OTP has expired. Re-Register to continue";

exports.VENDOR_NOT_PERMITTED = "Vendor is not verified or has been debarred"

0 comments on commit 846edff

Please sign in to comment.