The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/2fa/server/twoFactorRequired.ts

36 lines
1.1 KiB

import { Meteor } from 'meteor/meteor';
import { checkCodeForUser, ITwoFactorOptions } from './code/index';
import { IMethodThisType } from '../../../definition/IMethodThisType';
export function twoFactorRequired(fn: Function, options: ITwoFactorOptions): Function {
return function(this: IMethodThisType, ...args: any[]): any {
if (!this.userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'twoFactorRequired' });
}
// get two factor options from last item of args and remove it
const twoFactor = args.pop();
if (twoFactor) {
if (twoFactor.twoFactorCode && twoFactor.twoFactorMethod) {
checkCodeForUser({
user: this.userId,
connection: this.connection || undefined,
code: twoFactor.twoFactorCode,
method: twoFactor.twoFactorMethod,
options,
});
this.twoFactorChecked = true;
} else {
// if it was not two factor options, put it back
args.push(twoFactor);
}
}
if (!this.twoFactorChecked) {
checkCodeForUser({ user: this.userId, connection: this.connection || undefined, options });
}
return fn.apply(this, args);
};
}