genetic-orange
genetic-orange7mo ago

Access control for create Button doesnot work

<CreateButton accessControl={{ enabled: false }} type="primary" ghost icon={<PlusOutlined />}> Add New Master Source </CreateButton> the enabled is not working , CreateButton is from refineantd
2 Replies
kapa.ai
kapa.ai7mo ago
Hi @jash.s. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The accessControl prop in the CreateButton component from @refinedev/antd is used to control the visibility and accessibility of the button based on user permissions. The enabled property within accessControl is used to skip the access control check. If enabled is set to false, the access control check will not be skipped and the button will be hidden if the user does not have the necessary permissions. However, the accessControl prop only works when an accessControlProvider is provided to the <Refine/> component. If you haven't provided an accessControlProvider, the accessControl prop will not have any effect. Here is an example of how to use the accessControl prop:
import { CreateButton } from "@refinedev/antd";

export const MyListComponent = () => {
return <CreateButton accessControl={{ enabled: true, hideIfUnauthorized: true }} />;
};
import { CreateButton } from "@refinedev/antd";

export const MyListComponent = () => {
return <CreateButton accessControl={{ enabled: true, hideIfUnauthorized: true }} />;
};
In this example, the CreateButton will be displayed if the enabled property is true, and it will be hidden if the hideIfUnauthorized property is true and the user does not have the necessary permissions. If you have set enabled to false and the button is still visible, it could be because the user has the necessary permissions, or because you haven't provided an accessControlProvider to the <Refine/> component. For more information, you can refer to the refine documentation (https://refine.dev/docs/ui-integrations/ant-design/components/buttons/create-button#accesscontrol). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@1129363768661516329> kapa.ai is still learning and improving, please let us know how it did by reacting below