Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-rbac

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-rbac

Role Based Access Control for eggjs

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

egg-rbac

NPM version build status Test coverage David deps Known Vulnerabilities npm download

中文说明

Install

$ npm i egg-rbac --save

depend on egg version

egg-rbac versionegg version
0.3.01.x
0.4.02.0.0

From 0.4.0 version egg-rbac does not support egg 1.x.

depend on egg plugin

Usage

// {app_root}/config/plugin.js
exports.rbac = {
  enable: true,
  package: 'egg-rbac',
};

Configuration

config getRoleName

// {app_root}/config/config.default.js
exports.rbac = {
  /**
   * @param {object} ctx - egg context object
   * @return {object} promise, if resolve data is falsy, no role
   */
  * getRoleName(ctx) {
    return Promise.resolve('');
  },
};

Initialize roles and permissions

// {app_root/config/rbac.js}
'use strict';

exports.permissions = [
  // action_resource
  // { name: 'create_user', alias: '创建用户' },
  // { name: 'delete_user', alias: '删除用户' },
  // { name: 'query_user', alias: '查询用户' },
  // { name: 'edit_user', alias: '修改用户' },
];

exports.roles = [
  // { name: 'admin', alias: '管理员', grants: exports.permissions.map(item => item.name) },
];

see config/config.unittest.js for more detail.

Example

  1. see rbac-test
  2. practical example egg-rbac-example

Remarks

  • It will create a superadmin role which own all permissions.

License

MIT

Keywords

FAQs

Package last updated on 13 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc