Decentralized React App with CASL

Tram Ho

Decentralized React App with CASL

1. Introduction

Some Frameworks support:

2. Configuration for Reactjs

Read more README.MD if not satisfied https://github.com/stalniy/casl/tree/master/packages/casl-react

There is also a sample project for react: https://github.com/stalniy/casl-react-example

a. Install packages

b. Code

First we need to define two files, the ability.js configuration file and the Can.js component file. Where to put files, refer to How to structure React project by Mr. Dan Abramov ? .

Can.js

This is a component to check if the current user has the rights and display what he / she wants. For example:

ability.js

In this we need to input the array rules that the current user has no rights to the ability.

c. Integrated into the project

As explained above, we can hardcode permissions for each role or get it from the server after login

* Method 1:

Define a function and return and array rules

* Method 2:

Can retrieve data remote after login and pass to ability

d. How to use View More :

3. Credit:

Share the news now

Source : Viblo