2020-04-01 20:32:24 +00:00
|
|
|
import { settings } from '@rocket.chat/sdk';
|
|
|
|
|
2022-06-06 14:17:51 +00:00
|
|
|
import { TWO_FACTOR } from '../../containers/TwoFactor';
|
|
|
|
import EventEmitter from '../methods/helpers/events';
|
2020-04-01 20:32:24 +00:00
|
|
|
|
2022-01-12 12:54:04 +00:00
|
|
|
interface ITwoFactor {
|
|
|
|
method: string;
|
|
|
|
invalid: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const twoFactor = ({ method, invalid }: ITwoFactor): Promise<{ twoFactorCode: string; twoFactorMethod: string }> =>
|
2021-09-13 20:41:05 +00:00
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
EventEmitter.emit(TWO_FACTOR, {
|
|
|
|
method,
|
|
|
|
invalid,
|
|
|
|
cancel: () => reject(),
|
2022-01-12 12:54:04 +00:00
|
|
|
submit: (code: string) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
settings.customHeaders = {
|
|
|
|
...settings.customHeaders,
|
|
|
|
'x-2fa-code': code,
|
|
|
|
'x-2fa-method': method
|
|
|
|
};
|
|
|
|
resolve({ twoFactorCode: code, twoFactorMethod: method });
|
|
|
|
}
|
|
|
|
});
|
2020-04-01 20:32:24 +00:00
|
|
|
});
|