Skip to content

Commit 1fe3a64

Browse files
committed
fix: bug fixes
1 parent 145dc81 commit 1fe3a64

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/Adapters/Auth/mfa.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class MFAAdapter extends AuthAdapter {
9494
}
9595
const digits = opts.digits || 6;
9696
const period = opts.period || 30;
97+
const emailOTPExpiry = opts.emailOTPExpiry || 5*60; // Default to 5 minutes
9798
if (typeof digits !== 'number') {
9899
throw 'mfa.digits must be a number';
99100
}
@@ -107,8 +108,8 @@ class MFAAdapter extends AuthAdapter {
107108
throw 'mfa.period must be greater than 10';
108109
}
109110
if(this.email){
110-
if(this.emailOTPExpiry < 60){
111-
throw 'mfa.emailExpiry must be greater than 60 seconds';
111+
if(this.emailOTPExpiry < 5*60){
112+
throw 'mfa.emailExpiry must be greater than 5 minutes';
112113
}
113114
}
114115
const sendSMS = opts.sendSMS;
@@ -123,18 +124,19 @@ class MFAAdapter extends AuthAdapter {
123124
this.emailCallback = sendEmail;
124125
this.digits = digits;
125126
this.period = period;
127+
this.emailOTPExpiry = emailOTPExpiry;
126128
this.algorithm = opts.algorithm || 'SHA1';
127129
}
128130
validateSetUp(mfaData) {
129131
if (mfaData.mobile && this.sms) {
130132
return this.setupMobileOTP(mfaData.mobile);
131133
}
132-
if (this.totp) {
133-
return this.setupTOTP(mfaData);
134-
}
135134
if(mfaData.email && this.email){
136135
return this.setupEmailOTP(mfaData.email);
137136
}
137+
if (this.totp) {
138+
return this.setupTOTP(mfaData);
139+
}
138140
throw 'Invalid MFA data';
139141
}
140142
async validateLogin(loginData, _, req) {
@@ -308,15 +310,16 @@ class MFAAdapter extends AuthAdapter {
308310
}
309311

310312
async sendEmail(email) {
311-
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
312-
throw 'Invalid email address.';
313-
}
313+
const decodedEmail = email.replace(/___DOT___/g, '.')
314+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(decodedEmail)) {
315+
throw 'Invalid email address.';
316+
}
314317
let token = '';
315318
while (token.length < this.digits) {
316-
token += randomString(10).replace(/\D/g, '');
319+
token += (0, _cryptoUtils.randomString)(10).replace(/\D/g, '');
317320
}
318321
token = token.substring(0, this.digits);
319-
await Promise.resolve(this.emailCallback(token, email));
322+
await Promise.resolve(this.emailCallback(token, decodedEmail));
320323
const expiry = new Date(new Date().getTime() + this.emailOTPExpiry * 1000);
321324
return { token, expiry };
322325
}

0 commit comments

Comments
 (0)