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/client/lib/2fa/utils.ts

32 lines
978 B

import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
export const isTotpRequiredError = (
error: unknown,
): error is Meteor.Error & { error: 'totp-required' } =>
(error as { error?: unknown } | undefined)?.error === 'totp-required';
export const isTotpInvalidError = (
error: unknown,
): error is Meteor.Error & { error: 'totp-invalid' } =>
(error as { error?: unknown } | undefined)?.error === 'totp-invalid';
export const isLoginCancelledError = (error: unknown): error is Meteor.Error =>
error instanceof Meteor.Error && error.error === Accounts.LoginCancelledError.numericError;
export const reportError = <T>(error: T, callback?: (error?: T) => void): void => {
if (callback) {
callback(error);
return;
}
throw error;
};
export const convertError = <T>(error: T): Accounts.LoginCancelledError | T => {
if (isLoginCancelledError(error)) {
return new Accounts.LoginCancelledError(error.reason);
}
return error;
};