Skip to content

A user authorization library, integrates with MongoDB back-end, ported from Meteor accounts.

License

Notifications You must be signed in to change notification settings

alanning/roles-npm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

roles-npm

A user authorization library, integrates with MongoDB back-end, ported from Meteor accounts.

Based on the Meteor roles package Version 1.2.15.

Usage

In the directory with your project's package.json:

npm install @alanning/roles --save

In your app code:

import { Roles } from '@alanning/roles'
import { MongoClient } from 'mongodb'

// MongoDB connection
const db = await MongoClient.connect(MONGO_URL)
// Pass the users and roles collection to the Roles constructor
const roles = new Roles({
    users: db.collection('users')
    roles: db.collection('roles')
})
const isAuthorized = await roles.userIsInRole(loggedInUser, 'manager', 'acme')  

The roles instance has all the methods documented here.

Build

npm run build

Testing

Start your local MongoDB server:

mongod

Then:

npm test

A roles-npm database will be used during testing. Feel free to delete that database after the tests are run.

About

A user authorization library, integrates with MongoDB back-end, ported from Meteor accounts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published