Coder Social home page Coder Social logo

role-based-access-control's Introduction

Steps to run the application

  • Install NodeJS

  • Clone or Download this Repository

  • Run npm install

  • Getting started with database The database user here is Mongoose which is a MongoDB object modeling tool designed to work in an asynchronous environment. You can get started with mongoose (https://mongoosejs.com/docs/) or you can read thisawesome article on getting started with Mongoose. Fill your databse url in the keys_dev.js file inside the config folder

  • Run start script with npm start-dev

Usage

Only the user with the superadmin permission will be able to access this route

const access_rules= require('./Permissions/access_rules');
app.use('/api/permissions',access_rules.canAccessRole(['superadmin']),permissions);

canAccessRole is fully customizable and you can also pass multiple roles to it.

const access_rules= require('./Permissions/access_rules');
app.use('/api/permissions',access_rules.canAccessRole(['admin','standard']),permissions);

The above will allow the user with admin and standard permission to access the route.

You can also customize it such that user with certain level of access i.e read access or write access can access or restrict from certain paths.

app.use('/api/role',access_rules.canAccessPermissions(['read']),role);

In the above example only the users who have read access will be able to access the above route. No other user can access this route.

For all api routes go to (https://role-base-access-control.herokuapp.com/api-docs/)

The database model for this dummy api is Here

role-based-access-control's People

Contributors

thakursachin467 avatar dependabot[bot] avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.