DEV Community

Rami Shaikha
Rami Shaikha

Posted on

Introducing ngx-smart-permissions – Lightweight Role & Permission Handling for Angular Apps

πŸ” Introducing ngx-smart-permissions – Lightweight Role & Permission Handling for Angular Apps

Managing access control in Angular apps shouldn't be complicated. That's why I built:

πŸ‘‰ ngx-smart-permissions

A lightweight, smart Angular library that lets you control access using roles and permissions, with clean APIs and full support for Angular 17 & 18.


🌟 Why ngx-smart-permissions?

Whether you're building an admin dashboard, an enterprise portal, or a CMS β€” managing permissions should be simple, declarative, and testable.

This library helps you:

  • βœ… Show/hide UI elements based on permissions or roles
  • βœ… Use powerful directives like *ngxHasPermission, *ngxHasRole
  • βœ… Protect routes using permission-based guards
  • βœ… Enable Super Admin override
  • βœ… Handle lazy-loaded modules
  • βœ… Work seamlessly with both NgModules and Standalone Components

πŸ”§ Installation

npm install ngx-smart-permissions
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Usage Example

βœ… UI Permission Check

<button *ngxHasPermission="'edit-post'">Edit</button>
Enter fullscreen mode Exit fullscreen mode

βœ… Role-based Check

<div *ngxHasRole="'admin'">Admin Area</div>
Enter fullscreen mode Exit fullscreen mode

πŸ” Route Guard Example

{
  path: 'dashboard',
  canActivate: [permissionGuard],
  data: { permission: 'view-dashboard' }
}
Enter fullscreen mode Exit fullscreen mode

πŸš€ Live Permission Switching

permissionService.switchPermissions(['edit-users', 'view-dashboard'], true, 'admin');
Enter fullscreen mode Exit fullscreen mode

Great for dynamic role switching and testing environments!


🌐 Try it Live


πŸ‘¨β€πŸ’» About the Author

Hi, I'm Rami Shaikha, a passionate Angular developer and OSS contributor.

Would love your feedback, stars ⭐, or even contributions if this library helps you.


❀️ Support & Feedback

If you're using Angular and want clean, scalable access control β€” give it a try!

Open to suggestions, improvements, or just a πŸ‘‹ in the comments.


🏷 Tags

#angular #typescript #webdev #opensource #frontend #authorization #accesscontrol

Top comments (0)