Hi everyone,
I’m new to Strapi and I’m currently developing an application with Strapi V4 using TypeScript.
I’m trying to override the sendConfirmationEmail method (in file node_modules/@strapi/plugin-users-permissions/server/services/user.js) which is called after a user registers in the register controller.
This functionality is provided by the Users & Permissions plugin when you enable the email confirmation.
My goal is to send an email defined in SendGrid using their template system instead of the default email of Strapi.
I added a strapi-server.ts file in the extension directory (src/extensions/users-permissions/strapi-server.ts) to override the method.
// src/extensions/users-permissions/strapi-server.ts
export default function (plugin) {
const registerController = plugin.controllers.auth.register;
plugin.controllers.auth.register = async (ctx) => {
// this code is executed
}
const sendConfirmationEmail = plugin.services.user.sendConfirmationEmail;
plugin.services.user.sendConfirmationEmail = async (user) => {
// this code is not executed
}
return plugin;
}
However, this does not seem to be working as expected. My custom method sendConfirmationEmail is not called.
I have already overridden the register method to add additional information to my user, and I call the original method to keep Strapi’s default behavior, this works as desired.
Can anyone help me figure out what I’m missing or doing wrong?
And more generally, what is the procedure for redefining a method of a plugin service? I would also like to “decorate” the send method of the email plugin to add behavior based on my environment.
Thank you!
This topic has been created from a Discord post (1248558673811476490) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord