7

I'm using Strapi for my API and Back office. Everything works fine except one thing: I can't figure out how to override the controller that is used for the forgot password feature. I've tried to follow the documentation, especially this page : https://strapi.io/documentation/3.0.0-beta.x/admin-panel/customization.html#development-mode but no chance.

Here what I've tried :

  1. Create a folder admin at the root of the project, inside which I created controller/Auth.js. In this file I created my custom forgotPassword function but it's not called.
  2. Add the file admin/config/routes.json, my controller got the same name but I thought that maybe I need to repeat the route here to override, still not successful.
  3. I saw on some page that to get what I was searching I needed to put those files (config/routes.json and controller/Auth.js) inside /extensions/user-permissions/admin, but it's still not working.

Whatever I try, it's always the default forgot password controller that is called, from the strapi-admin node modules.

Any help would be greatly appreciated, I don't see what I'm missing here.

Ghislain
  • 115
  • 1
  • 5

1 Answers1

4

It's normal, because your are not writing the file in the right place.

So I will help you with that.

First here is the documentation for the customization - https://strapi.io/documentation/3.0.0-beta.x/concepts/customization.html#plugin-extensions

Then we have to find the file in the code source we want to update.

Here is the function - https://github.com/strapi/strapi/blob/master/packages/strapi-plugin-users-permissions/controllers/Auth.js#L266

Based on the file path and the way to customize in strapi. You will have to create a file to this path extensions/users-permissions/controllers/Auth.js

Then create a module.exports with source code function and the update it.

this should work

Jim LAURIE
  • 3,859
  • 1
  • 11
  • 14
  • 1
    Thanks for your answer, however I wasn't able to make it work following your suggestion. I created a file `Auth.js`in `extensions/users-permissions/controllers`. In my file I got a module.exports and my controller `forgotPassword` to overwrite the native function. The controller starts with a `console.log` but it is never called, it still the controller from strapi-admin that gets called. Any idea of what I'm missing ? I read again the doc but can't see what's wrong – Ghislain Jun 01 '20 at 09:08
  • @JiLan I've been searching around for a similar case and I think you may want to also check `resetPassword` instead of `forgotPassword`... – Ant Sep 16 '20 at 16:35