Error Can't resolve 'fs'
Hello everyone, I'm facing an error integrating Casbin accessControlProvider
here is the code for accessControlProvider I followed from the documentation
accessControlProvider={{
can: async ({ resource, action }) => {
const enforcer = await newEnforcer(model, adapter);
const can = await enforcer.enforce('admin', resource, action);
return { can };
},
}}
And its showing Can't resolve 'fs'![No description](https://cdn.answeroverflow.com/1087657959829549106/Screenshot_2023-03-21_at_4.37.05_PM.png)
5 Replies
Hey @franzdev! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
----------------------
To resolve the "Can't resolve 'fs'" error when integrating Casbin with refine, you need to configure polyfills for
casbin
to work in a browser environment. You can use react-app-rewired
to override some of the configurations of your app. Follow these steps:
1. Add react-app-rewired
to your project:
2. Update the scripts in your package.json
:
3. Add the following packages:
4. Include the config-overrides.js
file in the root of your app folder. You can find the file here (https://github.com/anewman15/refine/blob/pixels-admin/examples/pixels-admin/config-overrides.js).
After completing these steps, the error should be resolved. For more information, refer to the Browser Fallbacks for Casbin section (https://refine.dev/blog/refine-pixels-6/#browser-fallbacks-for-casbin) in the refine blog.
----------------------Implementing Role Based Access Control | refine
We'll implement Role Based Access Control (RBAC)
<@619660544319684609> kapa.ai is still learning and improving, please let us how it did by reacting below
flat-fuchsia•2y ago
Now I'm getting this error
![No description](https://cdn.answeroverflow.com/1087662263156088852/Screenshot_2023-03-21_at_5.00.36_PM.png)
flat-fuchsia•2y ago
It's now working fine I refer to this code
https://codesandbox.io/embed/github/refinedev/refine/tree/master/examples/access-control-casbin?view=preview&theme=dark&codemirror=1
access-control-casbin - CodeSandbox
access-control-casbin using @refinedev/antd, @refinedev/cli, @refinedev/core, @refinedev/react-router-v6, @refinedev/simple-rest, @types/node, @types/react, @types/react-dom, @uiw/react-md-editor