Skip to content

Handle authorization in your javascript applications like a boss

License

Notifications You must be signed in to change notification settings

SampaioLeal/vigia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vigia

Handle authorization in your javascript applications like a boss

Examples

import { Role } from "https://deno.land/x/vigia/mod.ts";

const userRole = new Role();

userRole.buildPermissions([
  ["can", "make", "coffee"],
  ["cannot", "make", "sandwich"],
]);

userRole.can("make", "coffee"); // true
userRole.cannot("make", "coffee"); // false

if (userRole.can("make", "coffee")) {
  // work more...
} else {
  // work to buy more coffee
}

You can choose the builder pattern to set the role permissions.

import { Role } from "https://deno.land/x/vigia/mod.ts";

const userRole = new Role();

userRole.set("can", "make", "coffee").set("cannot", "make", "sandwich");

userRole.can("make", "coffee"); // true
userRole.cannot("make", "coffee"); // false

if (userRole.can("make", "coffee")) {
  // work more...
} else {
  // work to buy more coffee
}

You can also save and/or fetch your roles by using the getRaw() method that returns an array of abilities.

const userRole = new Role();

userRole.buildPermissions([
  ["can", "make", "coffee"],
  ["cannot", "make", "sandwich"],
]);

userRole.getRaw(); // [ ["can", "make", "coffee"], ["cannot", "make", "sandwich"] ]

About

Handle authorization in your javascript applications like a boss

Resources

License

Stars

Watchers

Forks

Packages

No packages published