secure-role-component

1.0.6 • Public • Published

####The module renders components based on roles.

#####Pre-requisites

Roles must be stored in the local storage with the key as roles.
The values must be something like ROLE_USER,ROLE_ADMIN

#####Usage:

import React from 'react';
import  Secure from "secure-role-component"

class Dashboard extends  React.Component {
 render() {
     return (

         <Secure roles={['ROLE_USER','ROLE_ADMIN']} components={
                        <Col lg={4}>
                     <div>Hello World!</div>
                     </Col> }/>)
     }
}
Props explanantion
roles : Pass array of roles you want the user to have to view the component.
components: Pass the components you want to render conditionally.

Notes on how to use:
Make an API Call to your backend and get the roles the logged in user has.
Save the roles in local storage. Use the secure-role-component module as above to get conditional rendering.

Readme

Keywords

none

Package Sidebar

Install

npm i secure-role-component

Weekly Downloads

1

Version

1.0.6

License

none

Unpacked Size

62.7 kB

Total Files

7

Last publish

Collaborators

  • rajalive28