Customize Strapi users permissions services

I want to overwrite sendConfirmationEmail function in node_modules/strapi-plugin-users-permissions/services/User.js
1- How to overwrite this service?
2- Is it possible to overwrite sendConfirmationEmail function only?

Hey @samasarin,

To overwrite plugins you can use extensions. By copying ./node_modules/strapi-plugin-users-permissions/services/User.js to ./extensions/users-permissions/services/User.js and removing all the unused functions you can modify the senConfirmationEmail.

For example you will get:

'use strict';

const crypto = require('crypto');
const { sanitizeEntity, getAbsoluteServerUrl } = require('strapi-utils');

module.exports = {
  async sendConfirmationEmail(user) {
    // ...

(Do note the warning in the docs about use extensions and upgrading your strapi version :warning:)

Good luck!

1 Like

Thanks for your reply @MattieBelt. I’m going to try this approach today. I will share the result here.

@MattieBelt It worked great as expected. Thanks a lot. But for other guys that might use this approach please consider the update warning:
When using extensions you will need to update your code whenever you upgrade your strapi version. Not updating and comparing your extensions with the new changes on the repository, can break your app in unexpected ways that we cannot predict in the migration guides.

1 Like

You can close this topic for now.

Great to hear, and yes indeed, do note the warning, although it isn’t something to scare you off :wink:

I have marked my answer as the solution (and moved it to the Q&A section), closing isn’t needed.

1 Like

@MattieBelt Any solutions for Strapi v4?

1 Like

Hi @MattieBelt,

by removing all the unused functions like you explained, will these functions then be unavailable completely or will they be inherited from the original extension?

It will be inherited

1 Like

Thanks, I can confirm that.

Hello @samasarin,
could you please advice how we can use env variables within extensions?