Files
modstagram-back/utils/otpExpiry.js
2026-07-07 12:29:12 +03:30

17 lines
392 B
JavaScript

const OTP_VALID_MS = 3 * 60 * 1000
const isOtpExpired = (user) => {
if (!user?.otp) return true
if (!user?.otpSentAt) return false
return Date.now() - new Date(user.otpSentAt).getTime() > OTP_VALID_MS
}
const clearOtp = (UserModel, mobile) =>
UserModel.updateOne({ mobile }, { $set: { otp: null, otpSentAt: null } })
module.exports = {
OTP_VALID_MS,
isOtpExpired,
clearOtp
}