I'm using otplib: https://github.com/yeojz/otplib
Each user has its own secret stored in a database. When a user logs in for 2FA I run totp.generate(secret);
on the user's secret. I set step to 5 minutes
const { totp } = require('otplib');
totp.options = { step: 300 }; // 5 minutes
How do I ensure everytime I generate a token it will start from 0 seconds? Currently its the time remaining for each token is between [0, 300] depending on the time I generate. Is totp not what I want to use ?
For example, consider when a user generates a totp through logging in, their time remaining is 1 second. By the time they type in their pin the otp already changed, so it would error, even though they just generated it.
I want consistent time. When I generate a token, I want the token to be valid for 300 seconds not randomly [0,300]. How do I achieve this?