Resources on navbar not showing after login
After logging in, resources on navbar are not shown until I refresh page. I can't figure it out as nothing is showing in console and everything is as usual in network tab.
<Refine /> component or how your routing is configured. resources property of the <Refine /> component. These resources define the routes for the CRUD pages. The routes are used by Refine hooks and components. For example, the hook uses the list, create, edit, and show routes to navigate between the pages. Also, data hooks like useTable use the resource name when you don't pass the resource prop. You can refer to the <Refine /> component documentation for more information on the available props source (https://refine.dev/blog/react-admin-panel#adding-resources-and-connect-pages-to-refine-app).routerProvider prop, you'll also need to update the usage of hook, which is deprecated and only works with the legacy router providers. You can replace the usage from with the hook source (https://github.com/refinedev/refine/discussions/3902).options of the , there's a option. If this option is set to true, buttons will be hidden instead of disabled when access control returns . Make sure this option is set correctly for your needs source (https://refine.dev/docs/authorization/access-control-provider#buttons).<Refine /> component. If resources are not set up correctly, they might not appear in the sider menu source (https://github.com/refinedev/refine/issues/4852).authProvider to get the user's role, and then uses an enforcer (presumably from a library like ) to check if the user has permission to perform the action on the resource.authProvider is correctly returning the user's role. You can add a after the call to check this.resource and action values: Make sure the resource and action values passed to the function are what you expect. You can add a at the start of the function to check this.authProvider and is used to get the user's permissions. If it's not being called after login, it could be due to a few reasons:authProvider setup: Make sure the function is defined in your authProvider and is being exported correctly.login function: The function is typically called after the login function in the authProvider. Make sure your login function is correctly setting up the user's session and returning a successful response.authProvider and logs a message if the user has admin permissions source (https://refine.dev/docs/authentication/hooks/use-permissions/).useNavigationuseRouterContextuseRouterContextLinkuseLinkAccessControlProviderAccessControlProviderAccessControlProviderAccessControlProviderAccessControlProvidercancancancancancancan{ can: true }{ can: false }{ can: false }hideIfUnauthorizedhideIfUnauthorizedaccessControlaccessControlconst role = await authProvider.getPermissions?.();
export const accessControlProvider = {
can: async ({ resource, action }: CanParams): Promise<CanReturnType> => {
const enforcer = await newEnforcer(model, adapter);
const can = await enforcer.enforce(role, resource, action);
return Promise.resolve({
can,
});
},
};accessControlProvideraccessControlProvidergetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionsgetPermissionscasbinconsole.log(role)enforceenforceconsole.log(can)console.log(resource, action)usePermissionsusePermissionsusePermissionsusePermissionsexport const accessControlProvider = {
can: async ({ resource, action }: CanParams): Promise<CanReturnType> => {
const role = await authProvider.getPermissions?.();
const enforcer = await newEnforcer(model, adapter);
const can = await enforcer.enforce(role, resource, action);
return Promise.resolve({
can,
});
},
};fetchPermissionsimport { usePermissions } from "@refinedev/core";
const { data } = usePermissions();
if (data?.includes("admin")) {
console.log("User has admin permissions");
} import { useQuery } from 'react-query';
// Define a function to fetch the permissions
async function fetchPermissions() {
return await authProvider.getPermissions?.();
}
export const accessControlProvider = {
can: async ({ resource, action }: CanParams): Promise<CanReturnType> => {
// Use react-query to fetch the permissions
const { data: role } = useQuery('permissions', fetchPermissions);
const enforcer = await newEnforcer(model, adapter);
const can = await enforcer.enforce(role, resource, action);
return Promise.resolve({
can,
});
},
};