import { MeteorError } from '@rocket.chat/core-services'; import type { ServerMethods } from '@rocket.chat/ddp-client'; import { Meteor } from 'meteor/meteor'; import { twoFactorRequired } from '../../lib/2fa/twoFactorRequired'; import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger'; import { resetUserE2EEncriptionKey } from '../../lib/resetUserE2EKey'; declare module '@rocket.chat/ddp-client' { // eslint-disable-next-line @typescript-eslint/naming-convention interface ServerMethods { 'e2e.resetOwnE2EKey'(): Promise; } } Meteor.methods({ 'e2e.resetOwnE2EKey': twoFactorRequired(async () => { methodDeprecationLogger.method('e2e.resetOwnE2EKey', '9.0.0', '/v1/users.resetE2EKey'); const userId = Meteor.userId(); if (!userId) { throw new MeteorError('error-invalid-user', 'Invalid user', { method: 'resetOwnE2EKey', }); } if (!(await resetUserE2EEncriptionKey(userId, false))) { throw new MeteorError('failed-reset-e2e-password', 'Failed to reset E2E password', { method: 'resetOwnE2EKey', }); } return true; }), });