react-guarded
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

react-guarded

Simple Guard component for react js.

NPM

Installation:

Install react-guarded via npm

npm install react-guarded --save

Integration

// index.js
import {Permissions, Role} from 'react-guarded';
 
 
Permissions.insert(['ADD', 'UPDATE']);
// Set permissions for current user
 
Role.set('admin');
// set role for current user
 
// app.component.js
import {Guarded} from 'react-guarded';
 
 
<Guarded permissions={['UPDATE']} > click update ...</Guarded>

Properties (optional)

permissions - [?string[]]

Permissions array for Guarded section in application.

 <Guarded permissions={['UPDATE', 'MODIFY']} > click update ...</Guarded>

Owner - [?any - React Component]

Guarded parent component.

Permissions array for Guarded section in application.

 <Guarded Owner={MyComponent} componentprop1={'balabala'} componentprop2={'balabala'} permissions={['UPDATE', 'MODIFY']} > click update ...</Guarded>

oneOf - [?boolean]

If oneOf properties are enabled, the existence of one of the permissions list is sufficient.

 <Guarded oneOf permissions={['UPDATE', 'MODIFY']} > click update ...</Guarded>

hasRole - [?string[]]

Has role properties list all of roles for guarded area.

 <Guarded oneOf hasRole={['admin', 'user']} permissions={['UPDATE', 'MODIFY']} > click update ...</Guarded>

Supported

If you have ideas for more “How To” recipes that should be on this page, Issues

Package Sidebar

Install

npm i react-guarded

Weekly Downloads

0

Version

1.0.9

License

ISC

Unpacked Size

7.83 kB

Total Files

4

Last publish

Collaborators

  • h4mit