Access parent or parentName or dataProviderName inside of the accessControlProvider Property
We are currently working on the integration of ACLs into our project, but we're stumbling across the passed in
params
object. First of all for clarification some code:
The code does what it should, but only on the Landingpage, where the params.resource
will always hold the actual resource it is asking for.
As soon as we move to the List-Page, the checks are run again, but this time for every resource item (i.e. specific post) inside of the list. This time the params.resource
is {id: 1}
where it holds the resource items ID. This means we can no longer access the params?.resource?.meta?.parent
. I thought about using useResource
, but that seems a bit like a hacky workaround to me.
Any idea on how to solve this? π
31 Replies
Hi @bastianwegge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Hmm, I don't know enough to give you a confident answer yet. However, you can refer to the refine documentation on Access Control Provider (https://refine.dev/docs/api-reference/core/providers/accessControl-provider) for more information on how to work with the
params
object and access control in refine.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below
afraid-scarletβ’15mo ago
@kapa.ai can I get the active Resource inside my App.tsx file?
Let me check the knowledge base for you. One moment! :books:
----------------------
Yes, you can get the active resource inside your
App.tsx
file using the useResource
hook. Here's an example of how to use it:
You can find more information about the useResource
hook in the refine documentation (https://refine.dev/docs/api-reference/core/hooks/resource/useResource/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below
afraid-scarletβ’15mo ago
@kapa.ai that does not work, as it's probably out of Context of Refine
Let me check the knowledge base for you. One moment! :books:
----------------------
Apologies for the confusion. You're right, using the
useResource
hook directly in App.tsx
might not work as it's outside the context of Refine. Instead, you can create a wrapper component inside the <Refine>
component and use the useResource
hook there. Here's an example:
This way, you can access the active resource within the context of Refine.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below
afraid-scarletβ’15mo ago
@kapa.ai nice work, but how would you then go ahead and pass the results of the useResource hook back to the parent Refine component for Authorization? π
Let me check the knowledge base for you. One moment! :books:
----------------------
To pass the results of the
useResource
hook back to the parent Refine component for Authorization, you can create a custom Access Control Provider and pass it to the accessControlProvider
prop of the <Refine>
component. Here's an example:
1. Create a custom Access Control Provider component:
2. Use the custom Access Control Provider component inside the <Refine>
component:
This way, you can access the active resource within the context of Refine and use it for authorization in your custom Access Control Provider.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below
afraid-scarletβ’15mo ago
@kapa.ai you are printing out double quotes instead of single quotes.
Let me check the knowledge base for you. One moment! :books:
----------------------
Apologies for the formatting issue in my previous responses. Here's the corrected example:
1. Create a custom Access Control Provider component:
2. Use the custom Access Control Provider component inside the
<Refine>
component:
This way, you can access the active resource within the context of Refine and use it for authorization in your custom Access Control Provider.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@317433576721219584> kapa.ai is still learning and improving, please let us how it did by reacting below
afraid-scarletβ’15mo ago
That does unfortunately not work as you cannot use hooks inside of Properties of Components π
@kapa.ai can you remove your answers?