Skip to content

casbin-js/node-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 permission, which can be passed to Casbin.js at the frontend.

Installation

npm install --save @casbinjs/server-utils
# or
yarn add @casbinjs/server-utils

Example

import {getUserPermission} from '@casbinjs/server-utils'

// In your Restful API
private async setRouter(): Promise<void> {
    this.app.get('/api/casbin', async (req: express.Request, res: express.Response) => {
        // Get the user identity from URL.
        const user = String(req.query["casbin_user"]);
        // Generate the valid permission string. You need to inialize a Casbin enforcer before calling the `getUserPermission` 
        const permission = await getUserPermission(enforcer, user);
        res.status(200).json({
            message: 'ok',
            data: permission
        })
    })
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published