Skip to content

Aroin/react-guarded

Repository files navigation

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

About

Simple Guard component for react js.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published