Skip to content

Commit e835ac3

Browse files
committed
fix: minor bug fixes
1 parent 854b955 commit e835ac3

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/Adapters/Auth/mfa.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @param {Array<String>} options.options - Supported MFA methods. Must include `"SMS"` or `"TOTP"`.
77
* @param {Number} [options.digits=6] - The number of digits for the one-time password (OTP). Must be between 4 and 10.
88
* @param {Number} [options.period=30] - The validity period of the OTP in seconds. Must be greater than 10.
9+
* @param {Object} [options.period={TOTP:30,SMS:30,EMAIL:150}] - The validity period of the OTP in seconds for different mfa factors. Must be greater than 30.
910
* @param {String} [options.algorithm="SHA1"] - The algorithm used for TOTP generation. Defaults to `"SHA1"`.
1011
* @param {Function} [options.sendSMS] - A callback function for sending SMS OTPs. Required if `"SMS"` is included in `options`.
1112
*
@@ -92,7 +93,7 @@ class MFAAdapter extends AuthAdapter {
9293
throw 'mfa.options must include SMS or TOTP or EMAIL';
9394
}
9495
const digits = opts.digits || 6;
95-
const period = opts.period || 30;
96+
this.period = {};
9697

9798
// Define default periods for each method
9899
const defaultPeriods = {
@@ -103,34 +104,29 @@ class MFAAdapter extends AuthAdapter {
103104

104105
if (typeof opts.period === 'number') {
105106
validOptions.forEach(method => {
106-
this.period[method] = this.period;
107+
this.period[method] = opts.period;
107108
});
108109
} else if (opts.period && typeof opts.period === 'object') {
109-
Object.keys(this.period).forEach(method => {
110-
if (this.periods.hasOwnProperty(method) && typeof this.period[method] === 'number') {
111-
this.period[method] = this.period[method] ?? defaultPeriods[method] ?? 30;
110+
Object.keys(opts.period).forEach(method => {
111+
if (opts.period.hasOwnProperty(method) && typeof opts.period[method] === 'number') {
112+
this.period[method] = opts.period[method] ?? defaultPeriods[method] ?? 30;
112113
}
113114
});
114-
this.period = { ...opts.period };
115115
} else {
116116
validOptions.forEach(method => {
117117
this.period[method] = defaultPeriods[method] ?? 30;
118118
});
119119
}
120-
121120
if (typeof digits !== 'number') {
122121
throw 'mfa.digits must be a number';
123122
}
124-
if (typeof period !== 'number') {
125-
throw 'mfa.period must be a number';
126-
}
127123
if (digits < 4 || digits > 10) {
128124
throw 'mfa.digits must be between 4 and 10';
129125
}
130126

131127
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`;
128+
if (typeof this.period[method] !== 'number' || this.period[method] < 30) {
129+
throw `mfa.period.${method} must be a number greater than or equal to 30`;
134130
}
135131
});
136132

@@ -145,7 +141,6 @@ class MFAAdapter extends AuthAdapter {
145141
this.smsCallback = sendSMS;
146142
this.emailCallback = sendEmail;
147143
this.digits = digits;
148-
this.period = period;
149144
this.algorithm = opts.algorithm || 'SHA1';
150145
}
151146
validateSetUp(mfaData) {

0 commit comments

Comments
 (0)