NetPress Permissions
@admicaa/netpress-permissions is the Laravel-style authorization package for NetPress. It ships roles, permissions, polymorphic assignments, an Express-friendly AuthGuard middleware, and a publisher that wires everything into your application with a single command.
Authentication guards themselves live in NetPress core under Auth from @admicaa/netpress. This package sits one layer above that and focuses on authorization.
For the core framework runtime, guards, policies, controllers, and the shared can() helper, start with @admicaa/netpress and the main framework project: <https://github.com/admicaa/netpress>
What You Get
RoleandPermissionEloquent-style models backed by KnexHasRolesandHasPermissionstraits composable throughAuthorizable(BaseModel)- Polymorphic assignments so any model can carry roles or direct permissions
- An
AuthGuardmiddleware that wraps policy-aware ability and permission checks for Express 5 routes - Permission groups for clean UI display logic (e.g.
posts,users,billing) registerPolicyintegration for class-based resource policies- A
vendor:publishflow that drops a config file, a migration, and a service provider into your app
When To Reach For It
You need NetPress Permissions when your app has more than a couple of binary role checks and you want a predictable, test-friendly pattern for:
- assigning users to roles, and roles to permissions;
- granting direct per-model permissions without creating a role first;
- resolving resource policies and permission names through the same
can()helper; - guarding Express routes with a one-liner (
AuthGuard.can('posts.publish')); - separating permissions into groups so your admin UI can render them sanely.
A Thirty Second Taste
import { BaseModel } from '@admicaa/netpress';
import {
Authorizable,
Permission,
Role,
} from '@admicaa/netpress-permissions';
class User extends Authorizable(BaseModel) {
static table = 'users';
}
const editor = await Role.findOrCreate('editor');
const publish = await Permission.findOrCreate('posts.publish', { group: 'posts' });
await editor.givePermissionTo(publish);
const user = await User.create({ name: 'Amina' });
await user.assignRole(editor);
await user.can('posts.publish'); // true
Where To Next
- Run through Installation to install the package and publish its assets.
- Read Roles and Permissions for the mental model.
- Read Policies if you want record-level rules.
- Jump to Auth Guard when you are ready to wire Express middleware.