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

@blackbox-vision/ra-rbac

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blackbox-vision/ra-rbac

> TODO: description

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by400%
Maintainers
2
Weekly downloads
 
Created
Source

RA RBAC License: MIT

Role based Access Control for React Admin.

Install

You can install this library via NPM or YARN.

NPM

npm i @blackbox-vision/ra-rbac

YARN

yarn add @blackbox-vision/ra-rbac

Use case

You need to have fine grained permissions over your React Admin app.

Usage

The usage is really simple:

  1. Define your createCanActivate function like the following:
// createCanActivate.ts
import { Permission } from '@blackbox-vision/ra-rbac';

// Your can activate logic
export const createCanActivate = (permissions: Permission[]) => (resource: string, action: string, fields?: string[]) => {
  if (Array.isArray(fields)) {
    return fields.reduce((acc, field) => ({
      ...acc,
      [field]: true
    }), {})
  }

  return true;
}
  1. Import RbacProvider and RbacResource and wrap your React Admin with it:
// App.tsx
import React from 'react';
import { Admin } from 'react-admin';
import jsonServerProvider from 'ra-data-json-server';
import { createCanActivate } from './createCanActivate';

import { RbacProvider, RbacResource as Resource } from '@blackbox-vision/ra-rbac';

const dataProvider = jsonServerProvider('https://jsonplaceholder.typicode.com');

export const App = () => {
  return (
    <RbacProvider createCanActivate={createCanActivate}>
      <Admin dataProvider={dataProvider}>
        <Resource name="users" list={ListGuesser} />
      </Admin>
    </RbacProvider>
  );
};

App.displayName = "App";

Props

RbacProvider

RbacProvider has the following props:

PropertiesTypesDefault ValueDescription
createCanActivateFunction() => () => trueThe menu items to render

RbacResource

RbacResource has the same props as RA Resource.

Issues

Please, open an issue following one of the issues templates. We will do our best to fix them.

Contributing

If you want to contribute to this project see contributing for more information.

License

Distributed under the MIT license. See LICENSE for more information.

FAQs

Package last updated on 20 Mar 2021

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