Skip to content

Commit 854b955

Browse files
committed
fix: period changes
1 parent 57f000f commit 854b955

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Adapters/Auth/mfa.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,12 @@ class MFAAdapter extends AuthAdapter {
127127
if (digits < 4 || digits > 10) {
128128
throw 'mfa.digits must be between 4 and 10';
129129
}
130-
if (period < 10) {
131-
throw 'mfa.period must be greater than 10';
132-
}
130+
131+
validOptions.forEach(method => {
132+
if (typeof this.period[method] !== 'number' || this.period[method] < 10) {
133+
throw `mfa.period.${method} must be a number greater than or equal to 10`;
134+
}
135+
});
133136

134137
const sendSMS = opts.sendSMS;
135138
const sendEmail = opts.sendEmail;
@@ -232,7 +235,7 @@ class MFAAdapter extends AuthAdapter {
232235
const totp = new TOTP({
233236
algorithm: this.algorithm,
234237
digits: this.digits,
235-
period: this.period,
238+
period: this.period['TOTP'],
236239
secret: Secret.fromBase32(secret),
237240
});
238241
const valid = totp.validate({
@@ -337,7 +340,7 @@ class MFAAdapter extends AuthAdapter {
337340
}
338341
token = token.substring(0, this.digits);
339342
await Promise.resolve(this.smsCallback(token, mobile));
340-
const expiry = new Date(new Date().getTime() + this.period * 1000);
343+
const expiry = new Date(new Date().getTime() + this.period['SMS'] * 1000);
341344
return { token, expiry };
342345
}
343346

@@ -351,7 +354,7 @@ class MFAAdapter extends AuthAdapter {
351354
}
352355
token = token.substring(0, this.digits);
353356
await Promise.resolve(this.emailCallback(token, email));
354-
const expiry = new Date(new Date().getTime() + this.period * 1000);
357+
const expiry = new Date(new Date().getTime() + this.period['EMAIL'] * 1000);
355358
return { token, expiry };
356359
}
357360
async confirmSMSOTP(inputData, authData) {
@@ -401,7 +404,7 @@ class MFAAdapter extends AuthAdapter {
401404
const totp = new TOTP({
402405
algorithm: this.algorithm,
403406
digits: this.digits,
404-
period: this.period,
407+
period: this.period['TOTP'],
405408
secret: Secret.fromBase32(secret),
406409
});
407410
const valid = totp.validate({

0 commit comments

Comments
 (0)