question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extract file handling out (as a plugin?) to enable casbin to be used on React Native

See original GitHub issue

Hey,

firstly thanks for this awesome library!

I noticed that the frontend casbin library uses this under-the-hood, so I’m using this library on both microservice and Frontend.

However, I’d love to be able to use this library on React Native - which would work, but because the model loading from file uses the fs library, I can’t.

How likely/possible would it be to extract out model loading from a file/file handling to be a plugin/adapter to remove the need for fs? (I load the model and policy dynamically from the microservice).

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:29 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
nodececommented, May 3, 2021

@hsluoyz I agreed with @Sefriol and @harveyappleton idea.

The following is my integration steps:

  • create fs-adapter/model plugins in node-casbin project, we doesn’t need to export this in index.ts, node-casbin only uses string/memory adapter/model for cross-platform compatible.
    • fs-adapter
    • fs-model
    • memory-adapter
    • memory-model
  • remove ip package from node-casbin, this package uses os module, we can rewrite this package: #266
  • globMatch depends on the micromatch package, micromatch uses util provided by Node.js , so we need to consider to use minimatch instead of micromatch: #264
2reactions
Sefriolcommented, Apr 28, 2021

node-casbin includes os and fs module from Node. I tried to fix fs module by load fs and react-native-fs dynamically, but still failed, so I suggest to use the rn-nodeify to fix this error.

rn-nodeify looks really scary. I would rather keep fs as is than use it.

If covert the node-casbin to plain javascript, it looks good, but I’ll worry about losing some user, because node-casbin only accepts string model or policy, the user must to install plugin to load the file model or policy.

Same could be said for not doing the change: users won’t use Casbin since it does not work on their platform. Adapters are already in use and I do not see file adapter any more special than any other adapter.

In my opinion, since string / in memory adapter is usable between all platforms, it should be the default one and file adapter should be a plugin like the rest of them.

So pretty much two options:

  1. File-adapter will be deprecated in node-casbin and add it shall be a plugin. Plugin is added into devDependancies for the tests.
  2. We dynimically install/load a library based on the platform.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Access Control in Node.js with Fastify and Casbin - NearForm
Casbin offers a great foundation for access control, and Fastify's plugin system is perfect for abstracting away some of its complexity.
Read more >
How to allow react-native to enable support for JSX (extension ...
I have to use it to enable JSX support instead of rn-cli.config.js . Check out the documentation for the config file: ...
Read more >
Casbin · An authorization library that supports access control ...
An authorization library that supports access control models like ACL, RBAC, ABAC for Golang, Java, C/C++, Node.js, Javascript, PHP, Laravel, Python, .
Read more >
Ecosystem - Fastify
@fastify/cors, Enables the use of CORS in a Fastify application. ... process load with automatic handling of "Service Unavailable" plugin for Fastify.
Read more >
Extensions - Keycloak
Utility to ensure the desired configuration state for a realm based on a JSON or YAML file. Discord Identity Provider. Keycloak extension to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found