Strapi is a great project, but lacks of a good documentation concerning customization. This gist presents some of my findings / experiments to customize strapi.
My use-case: find
and findOne
need to be active to keep nested queries on other user-relations. But if I allow authenticated users to access these routes, they can access all users. So I customize these routes with my own policies:
// ./src/extensions/users-permissions/strapi-server.ts
export default (plugin) => {
plugin.routes["content-api"].routes.forEach((route) => {
if (route.handler === "user.findOne") {
route.config.policies = ["global::my-policy"]
}
if (route.handler === "user.find") {
route.config.policies = ["global::my-policy"]
}
})
return plugin
}
In my use-case, I want to add more services directly to the users without having to create a new plugin. This is possible by extending the user
service:
// ./src/extensions/users-permissions/strapi-server.ts
function myService() {
// do something
}
export default (plugin) => {
const oldServices = plugin.services.user
plugin.services.user = ({ strapi }) => {
return {
...oldServices({ strapi }),
myService,
}
}
return plugin
}