Skip to content

Commit

Permalink
refactor: remove send confirmation email method calls (server) (#35014)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosSpessatto authored Jan 31, 2025
1 parent 18ba1a0 commit 64a4fa9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { i18n } from '../../../../server/lib/i18n';
import { resetUserE2EEncriptionKey } from '../../../../server/lib/resetUserE2EKey';
import { sendWelcomeEmail } from '../../../../server/lib/sendWelcomeEmail';
import { saveUserPreferences } from '../../../../server/methods/saveUserPreferences';
import { sendConfirmationEmail } from '../../../../server/methods/sendConfirmationEmail';
import { getUserForCheck, emailCheck } from '../../../2fa/server/code';
import { resetTOTP } from '../../../2fa/server/functions/resetTOTP';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
Expand Down Expand Up @@ -953,7 +954,7 @@ API.v1.addRoute(
async post() {
const { email } = this.bodyParams;

if (await Meteor.callAsync('sendConfirmationEmail', email)) {
if (await sendConfirmationEmail(email)) {
return API.v1.success();
}
return API.v1.failure();
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/lib/server/functions/setEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as Mailer from '../../../mailer/server/api';
import { settings } from '../../../settings/server';
import { RateLimiter, validateEmailDomain } from '../lib';
import { checkEmailAvailability } from './checkEmailAvailability';
import { sendConfirmationEmail } from '../../../../server/methods/sendConfirmationEmail';

let html = '';
Meteor.startup(() => {
Expand Down Expand Up @@ -93,7 +94,7 @@ const _setEmail = async function (
email,
};
if (shouldSendVerificationEmail === true) {
await Meteor.callAsync('sendConfirmationEmail', result.email);
await sendConfirmationEmail(result.email);
}
return result;
};
Expand Down
40 changes: 22 additions & 18 deletions apps/meteor/server/methods/sendConfirmationEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@ import { Meteor } from 'meteor/meteor';

import { methodDeprecationLogger } from '../../app/lib/server/lib/deprecationWarningLogger';

Meteor.methods<ServerMethods>({
async sendConfirmationEmail(to) {
check(to, String);
export const sendConfirmationEmail = async (to: string): Promise<boolean> => {
check(to, String);

methodDeprecationLogger.method('sendConfirmationEmail', '7.0.0');
const email = to.trim();

const email = to.trim();
const user = await Users.findOneByEmailAddress(email, { projection: { _id: 1 } });

const user = await Users.findOneByEmailAddress(email, { projection: { _id: 1 } });
if (!user) {
return false;
}

if (!user) {
return false;
}
try {
Accounts.sendVerificationEmail(user._id, email);
return true;
} catch (error: any) {
throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${error.message}`, {
method: 'registerUser',
message: error.message,
});
}
};

try {
Accounts.sendVerificationEmail(user._id, email);
return true;
} catch (error: any) {
throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${error.message}`, {
method: 'registerUser',
message: error.message,
});
}
Meteor.methods<ServerMethods>({
async sendConfirmationEmail(to) {
methodDeprecationLogger.method('sendConfirmationEmail', '7.0.0');

return sendConfirmationEmail(to);
},
});

Expand Down

0 comments on commit 64a4fa9

Please sign in to comment.