Let's assume I have an endpoint GET /v1/admin/organizations/{organizationId}/facilities/{facilityId} . To access facility by Id the following conditions have to be met
- The endpoint is only accessible by users with role ADMIN
- To view organization with a particular ID current use has to be the owner of the organization
- To access faicility in organization the previous steps have to be met and additionally facility has to be in organization
How should I approach performing these 3 steps? As to number 1. I guess it's obvious to use a Guard. When it comes to 2 and 3 I have some doubts. For me these steps belong to the business logic rather than authorization but I may be wrong. Secondly, there will probably be many endpoints to the same resource, for example for update, delete. Moreover each facility can have places which would need /v1/admin/organizations/{organizationId}/facilities/{facilityId}/places/{placeId} and I would need to check if place is in a facility. The idea of creating multiple guards for checking each resource seems strange to me in such cases. Maybe I could create one individual guard for each endpoint for a particular resource which will check everything I need? Do you have any suggestions for this problem, maybe some articles or posts? Or maybe you have had similar requirements and implemented a solution for it?