
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
access-gate
Advanced tools
A powerful and flexible role-based access control (RBAC) library for modern JavaScript and TypeScript applications. Supports guards, policies, and advanced async capabilities for granular access control.
A powerful and flexible role-based access control (RBAC) library for modern JavaScript and TypeScript applications.
For full Documentation.
Install the package via npm or yarn:
npm install access-gate
# or
yarn add access-gate
import { Gate, Policy } from "access-gate";
const gate = new Gate();
// Define a policy
const postPolicy = new Policy("post");
postPolicy.define("update", (user, post) => user.id === post.authorId);
gate.addPolicy(postPolicy);
// Access the policy
const representative = gate.build({ id: 1 });
const decision = representative.access("post", "update").can({ authorId: 1 });
console.log(decision); // true
A Policy represents a set of actions that define access rules.
const postPolicy = new Policy("post");
postPolicy.define("view", (user, post) => true);
postPolicy.define("update", (user, post) => user.id === post.authorId);
gate.addPolicy(postPolicy);
Guards define global or contextual access rules.
gate.guard((user) => user.isAdmin);
Lazy guards are entity-specific restrictions.
gate.lazyGuard((user, post) => user.id === post.authorId);
A Decision object represents the result of evaluating a policy or guard.
const decision = representative.access("post", "view");
console.log(decision.can()); // true
The Gate class manages policies and guards.
addPolicy(policy: Policy): Adds a policy.guard(fn: Guard): Adds a global guard.lazyGuard(fn: LazyGuard): Adds a lazy guard.The Policy class defines a set of rules.
define(action: string, fn: (user, entity) => boolean): Defines a policy action.can(action: string): Evaluates if an action can be performed.The Representative class evaluates access based on policies and guards.
access(policy: string, action: string): Accesses a policy decision.can(entity?: object): Evaluates synchronous access.could(entity?: object): Evaluates async access.gate.asyncLazyGuard(async (user, resource) => {
const hasAccess = await someAsyncCheck(user, resource);
return hasAccess;
});
// provide
gate.guard((user, provide) => {
const role = getRole(user);
provide("role", role);
});
// inject
policy.define("update", (user, entity) => {
const role = this.inject("role");
return role === "user" && user.id === entity.authorId;
});
FAQs
A powerful and flexible role-based access control (RBAC) library for modern JavaScript and TypeScript applications. Supports guards, policies, and advanced async capabilities for granular access control.
We found that access-gate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.