like-gold
like-gold2mo ago

How do I combine multi-tenancy URI approach and accessProvider in Refine?

I have followed multi-tenancy guide, adding the tenantId into the route path. This works fine I am able to retrieve tenantId within my components. I am though unable to restrict my routes based on tenantId. When my custom accessProvider gets called it is not supplied with full route including tenantId and I cannot check if the user has access to a particular tenant route. P.S.:When the sider component calls my accessProvider - everything as expected the route is part of params.resource object.
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @duneatnight. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Refine, you can implement multi-tenancy by including the tenant information in your route definitions. For example, a products resource can have the route definition for list as /:tenantId/products [^1^]. However, to restrict routes based on tenantId, you would need to customize your accessProvider. The accessProvider in Refine is used to manage access control for resources and actions. It's a function that takes a resource and action as parameters and returns a boolean indicating whether the action is allowed on the resource [^2^]. Unfortunately, the accessProvider does not receive the full route including tenantId as a parameter. Therefore, you cannot directly check if the user has access to a particular tenant route within the accessProvider. One possible workaround could be to store the tenantId in a global state (like Redux or Context API) when you determine the tenant from the route in your component. Then, in your accessProvider, you can access this global state to check if the user has access to the particular tenant. Please note that this is a general approach and the actual implementation may vary based on your application's specific requirements and architecture. [^1^]: (https://refine.dev/docs/guides-concepts/multi-tenancy#configuring-multi-tenant-routes) [^2^]: (https://refine.dev/docs/api-references/providers/access-provider) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1051552034823872643> kapa.ai is still learning and improving, please let us know how it did by reacting below