All Projects β†’ shizpi β†’ react-redux-permissions

shizpi / react-redux-permissions

Licence: MIT license
A permissions library for react and redux applications.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-redux-permissions

React-Express-JWT-UserPortal
React.js & Express.js User portal Using Core UI, JWT, JWT Token, Refresh Token, Role & Permission management, User manamgenet, Event Log.
Stars: ✭ 22 (-50%)
Mutual labels:  permissions
easypermissions-ktx
πŸ”“ Kotlin version of the popular google/easypermissions wrapper library to simplify basic system permissions logic on Android M or higher.
Stars: ✭ 324 (+636.36%)
Mutual labels:  permissions
shyft
⬑ Shyft is a server-side framework for building powerful GraphQL APIs πŸš€
Stars: ✭ 56 (+27.27%)
Mutual labels:  permissions
laravel-zend-acl
Adds ACL to Laravel via Zend\Permissions\Acl component.
Stars: ✭ 41 (-6.82%)
Mutual labels:  permissions
django-hats
Role-based permissions system for Django. Everyone wears a different hat, some people wear multiple.
Stars: ✭ 21 (-52.27%)
Mutual labels:  permissions
django-cancan
πŸ”“Authorization library for Django
Stars: ✭ 36 (-18.18%)
Mutual labels:  permissions
nova-permissions
Add Permissions based authorization for your Nova installation via User-based Roles and Permissions. Roles are defined in the database whereas Permissions are defined in the code base.
Stars: ✭ 115 (+161.36%)
Mutual labels:  permissions
permission control system
This is an SDK which helps you to specify which user group (role) members have access to which actions in controllers.
Stars: ✭ 34 (-22.73%)
Mutual labels:  permissions
go-acl
Go library for manipulating ACLs on Windows
Stars: ✭ 97 (+120.45%)
Mutual labels:  permissions
permissions-ui
Background location permissions request helper
Stars: ✭ 53 (+20.45%)
Mutual labels:  permissions
LuckPerms-Mirai
LuckPerms on MiraiConsole
Stars: ✭ 58 (+31.82%)
Mutual labels:  permissions
permissions-flow
A simple library to make it easy requesting permissions in Android using Kotlin Coroutines.
Stars: ✭ 81 (+84.09%)
Mutual labels:  permissions
sentry
A lightweight (23KB) wrapper for inline Android permission checks/requests.
Stars: ✭ 22 (-50%)
Mutual labels:  permissions
permissionsql
πŸ” Middleware for keeping track of users, login states and permissions
Stars: ✭ 58 (+31.82%)
Mutual labels:  permissions
NoPermission
Android library for permissions request (updated 27.11.2017)
Stars: ✭ 106 (+140.91%)
Mutual labels:  permissions
rbac-tool
Rapid7 | insightCloudSec | Kubernetes RBAC Power Toys - Visualize, Analyze, Generate & Query
Stars: ✭ 546 (+1140.91%)
Mutual labels:  permissions
iam-policies
Iam policies implementation for create roles and manage permissions
Stars: ✭ 20 (-54.55%)
Mutual labels:  permissions
permissionUtil
Simple permission helper
Stars: ✭ 64 (+45.45%)
Mutual labels:  permissions
django-tabular-permissions
Display Django permissions in a HTML table that is translatable and easily customized.
Stars: ✭ 60 (+36.36%)
Mutual labels:  permissions
spree admin roles and access
Admin Roles And Access for Spree
Stars: ✭ 45 (+2.27%)
Mutual labels:  permissions

react-redux-permissions is a simple library to handle your react application permissions using redux.

Installation

npm i react-redux-permissions --save

or

yarn add react-redux-permissions

Features

  • Disable views and components
  • Provide a fallback component for users without permission
  • Designed for react-redux
  • High Order Component option

Requirements

  • node >= 4.0.0

Usage

Reducer

Import the reducer and pass it to your store:

import { createStore, combineReducers } from 'redux';

import { reducer as permissions } from "react-redux-permissions"

export function configureStore(initialState = {}) {
  return createStore(
    combineReducers({
      permissions
    }),
    initialState
  );
}

Actions

Add roles to the current user:

import { add } from "react-redux-permissions"

dispatch(add("manager"))
dispatch(add("canSeeMessages")) // Pretty much anything

Remove roles from the current user:

import { remove } from "react-redux-permissions"

dispatch(remove("canSeeMessages"))

Remove all roles. Useful once you logout.

import { clear } from "react-redux-permissions"

dispatch(clear())

Component

You can limit access to your views using the default Permissions component.

allowed

With the allowed prop, only users with one of the permissions will be able to see child components.

import Permissions from "react-redux-permissions"

...

<Permissions
  allowed={["paying"]}
>
  <Route path="/dashboard" component={DashboardView} />
</Permissions>

except

With the except prop, every user except the ones with the passed permission will be able to see child components.

import Permissions from "react-redux-permissions"

...

<Permissions
  except={["paying"]}
>
  <Route path="/dashboard" component={DashboardView} />
</Permissions>

fallbackElement

You can send a fallbackElement to show an alternative view for users without permission

import Permissions from "react-redux-permissions"

...

<Permissions
  except={["paying"]}
  fallbackElement={<DashboardDisabled />}
>
  <Route path="/dashboard" component={DashboardView} />
</Permissions>

HOC

You can also use a High Order Component to disable views and components:

Send allowed roles as the first argument and disallowed as the second argument. You can also provide a fallback component as second argument of the second function.

import { HOC as Permissions } from "react-redux-permissions"

const DashboardView = Permissions(
  ["admin", "paying"],
  ["trial"]
)(Dashboard, <ModuleDisabled view="Dashboard" />)

...

<Route path="/dashboard" component={DashboardView} />

Avoid using it like:

import { HOC as Permissions } from "react-redux-permissions"

const DashboardView = Permissions(["admin", "paying"], ["trial"])

...
render() {
  return (
    ...
    <Route path="/dashboard" component={DashboardView(Dashboard, <ModuleDisabled view="Dashboard" />)} />
    ...
  )
}

This approach inside render will make react mount the component again and cause undesired effects.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/shizpi/react-redux-permissions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The module is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].