To override the sendConfirmationEmail function in Strapi, you can use the concept of extensions. Here are the steps:
-
Copy the
User.jsfile from./node_modules/strapi-plugin-users-permissions/services/to./extensions/users-permissions/services/. -
In the copied
User.jsfile, remove all the unused functions and modify thesendConfirmationEmailfunction as per your requirements.
Here is an example of how your User.js file might look after modification:
'use strict';
const crypto = require('crypto');
const { sanitizeEntity, getAbsoluteServerUrl } = require('strapi-utils');
module.exports = {
async sendConfirmationEmail(user) {
// Your custom logic here...
},
};
Please note that you should be careful when using extensions and upgrading your Strapi version, as mentioned in the Strapi documentation (https://strapi.io/documentation/developer-docs/latest/concepts/customization.html#plugin-extensions).
Sources:
- Forum Post: Customize Strapi users permissions services (https://forum.strapi.io/t/2008)
- Github Issue: User registration returns Error 400 “Bad Request” when email confirmation is ON (https://github.com/strapi/strapi/issues/8600)