nsc-permission-control
permission controlled react component
Install
npm install --save nsc-permission-control
Usage
The permission controlled component will be rendered only when granted
covers required
:
import Permission from 'nsc-permission-control'
<Permission required="B001" granted="B001">
<button>permission B001 controlled button</button>
</Permission>
You can customize what to be rendered when not granted:
import Permission from 'nsc-permission-control'
<Permission required="B001" granted="B001" mode="advance">
{hasPermission => <button disabled={!hasPermission}>permission btn</button>}
</Permission>
'*' is a special permission code, which allows to access all.
You can define client side permission code, like:
import Permission, { defPermission } from 'nsc-permission-control'
defPermission('LOGIN', () => {
return window.isLogined
})
<Permission required="LOGIN">
<div>login protected content</div>
</Permission>
You can use hasPermission
alone:
import { hasPermission } from 'nsc-permission-control'
hasPermission(required, granted) // return true or false
props
- required
- granted
- mode
required
can be a string of permission code, or an array of permission code strings. So does granted
.
utils
- hasPermission
- defPermission
License
MIT © nsc-open