mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat(core): Add MFA (#4767)
https://linear.app/n8n/issue/ADO-947/sync-branch-with-master-and-fix-fe-e2e-tets --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
55
packages/cli/src/commands/mfa/disable.ts
Normal file
55
packages/cli/src/commands/mfa/disable.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { flags } from '@oclif/command';
|
||||
import * as Db from '@/Db';
|
||||
import { BaseCommand } from '../BaseCommand';
|
||||
|
||||
export class DisableMFACommand extends BaseCommand {
|
||||
static description = 'Disable MFA authentication for a user';
|
||||
|
||||
static examples = ['$ n8n mfa:disable --email=johndoe@example.com'];
|
||||
|
||||
static flags = {
|
||||
help: flags.help({ char: 'h' }),
|
||||
email: flags.string({
|
||||
description: 'The email of the user to disable the MFA authentication',
|
||||
}),
|
||||
};
|
||||
|
||||
async init() {
|
||||
await super.init();
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
const { flags } = this.parse(DisableMFACommand);
|
||||
|
||||
if (!flags.email) {
|
||||
this.logger.info('An email with --email must be provided');
|
||||
return;
|
||||
}
|
||||
|
||||
const updateOperationResult = await Db.collections.User.update(
|
||||
{ email: flags.email },
|
||||
{ mfaSecret: null, mfaRecoveryCodes: [], mfaEnabled: false },
|
||||
);
|
||||
|
||||
if (!updateOperationResult.affected) {
|
||||
this.reportUserDoesNotExistError(flags.email);
|
||||
return;
|
||||
}
|
||||
|
||||
this.reportSuccess(flags.email);
|
||||
}
|
||||
|
||||
async catch(error: Error) {
|
||||
this.logger.error('An error occurred while disabling MFA in account');
|
||||
this.logger.error(error.message);
|
||||
}
|
||||
|
||||
private reportSuccess(email: string) {
|
||||
this.logger.info(`Successfully disabled MFA for user with email: ${email}`);
|
||||
}
|
||||
|
||||
private reportUserDoesNotExistError(email: string) {
|
||||
this.logger.info(`User with email: ${email} does not exist`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user