Casbin.js Server Utilities for Node-Casbin
If you are using Casbin.js at your frontend and Node-Casbin as your backend Casbin service, you can install this package at your backend. This package provides a wrapper for generating the user profile passed to Casbin.js at the frontend.
Installation
npm install --save casbinjs-server-tool
# or
yarn add casbinjs-server-tool
Example
import CasbinServerTool from 'casbinjs-server-tool'
private async setRouter(): Promise<void> {
this.app.get('/api/casbin', async (req: express.Request, res: express.Response) => {
const user = String(req.query["casbin_user"]);
const casbinSvrTool = new CasbinServerTool(enforcer);
const profile = casbinSvrTool.genJsonProfile(user);
res.status(200).json({
message: 'ok',
data: profile
})
})
}