jolly-crimson
jolly-crimson•11mo ago

Case 0 not working

accessControlProvider={{
can: async ({ resource, action }) => {
let can = false;
const role = getUserRole();

if (role) {
switch (role) {
case 0:
console.log("User");
can = resource.startsWith('user/');
break;
case 2:
console.log("Admin");
can = resource.startsWith('admin/');
break;
}
}
return Promise.resolve({ can });
},
}}
accessControlProvider={{
can: async ({ resource, action }) => {
let can = false;
const role = getUserRole();

if (role) {
switch (role) {
case 0:
console.log("User");
can = resource.startsWith('user/');
break;
case 2:
console.log("Admin");
can = resource.startsWith('admin/');
break;
}
}
return Promise.resolve({ can });
},
}}
Case 0 not working I also want to clear cache on screen after new login
3 Replies
kapa.ai
kapa.ai•11mo ago
Hi @tads8799. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, it seems like you're trying to implement role-based access control in your refine application. However, it's not clear what the getUserRole() function does and how it determines the user's role. In the provided code, the can function checks if the resource starts with 'user/' or 'admin/' based on the user's role. If the role is 0 (which I assume corresponds to a user), it checks if the resource starts with 'user/'. If the role is 2 (which I assume corresponds to an admin), it checks if the resource starts with 'admin/'. If case 0 is not working, it might be because the resources for the user do not start with 'user/'. You should check how your resources are named and ensure they match the conditions in your can function. As for clearing the cache on the screen after a new login, refine doesn't provide a built-in way to do this. However, you can manually clear the local storage (where I assume you're storing your user data) when the user logs out or logs in. Here's an example:
const logout = () => {
// Clear local storage
localStorage.clear();
// Redirect user to login page or perform other logout actions
};
const logout = () => {
// Clear local storage
localStorage.clear();
// Redirect user to login page or perform other logout actions
};
Please note that this is a general JavaScript solution and might need to be adjusted based on your application's specific needs. For more information on access control in refine, you can refer to the Access Control Provider documentation (https://refine.dev/docs/core/providers/accessControl-provider/). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai•11mo ago
<@577213996344803338> kapa.ai is still learning and improving, please let us know how it did by reacting below
Omer
Omer•11mo ago
Hey @tads8799 , Could it be the same issue as this message? https://discord.com/channels/837692625737613362/1151085425503502356/1151658992871952424 👀