4.0.0 • Published 2 years ago

@blackbox-vision/ra-rbac v4.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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 canActivate function like the following:
// canActivate.ts
import { Permission } from "@blackbox-vision/ra-rbac";

export const canActivate = (
  permissions: Permission[] | any,
  resource: string,
  action: string,
  field?: string
) => {
  // Your can activate logic
  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 {
  RbacProvider,
  RbacResource as Resource,
} from "@blackbox-vision/ra-rbac";

import { canActivate } from "./canActivate";

export const App = () => {
  const dataProvider = jsonServerProvider(
    "https://jsonplaceholder.typicode.com"
  );

  return (
    <RbacProvider canActivate={canActivate}>
      <Admin dataProvider={dataProvider}>
        <Resource name="users" list={ListGuesser} />
      </Admin>
    </RbacProvider>
  );
};

App.displayName = "App";

Props

RbacProvider

RbacProvider has the following props:

PropertiesTypesDefault ValueDescription
canActivateFunction(p, r, a, f) => trueLogic to test if a user can perform an specific action or visualize an specific field

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.

4.0.0

2 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago