Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strapi custom auth controller

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.

like image 747
Ghislain Avatar asked Oct 16 '22 03:10

Ghislain


1 Answers

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

like image 179
Jim LAURIE Avatar answered Oct 18 '22 23:10

Jim LAURIE