I am using https://www.npmjs.com/package/speakeasy to generate OTP and i would like the expiry to 10 minutes.
Here is the code for generation
const generateOtp = function generateOtp() {
let token = speakeasy.totp({
secret:process.env.OTP_KEY,
encoding: 'base32',
digits:4,
window:10
});
return token;
}
Verify OTP
const verifyOtp = function verifyOtp(token){
let expiry = speakeasy.totp.verify({
secret:process.env.OTP_KEY,
encoding: 'base32',
token: token,
window:10
});
console.log(expiry)
}
But I don't know how to set the expiry to 10 minutes??
Reading the documentation you can find out that the base
stepis 30 seconds, so if you want to have an expiration time of 10 minutes you need to set up thestepto60. Then, using theverifyDeltamethod you should be able to check if the token expired.