Other Frameworks

While role-baker does not provide specific utilities for every framework, its core function, hasPermission, is all you need to implement role-based access control in various environments.

Core Function: hasPermission

The hasPermission function determines whether a user has the necessary permissions for a given resource and action. It can be seamlessly integrated into any framework to restrict access to UI components, API endpoints, middleware, route guards, higher-order components, or other functionalities.

Common Integration Approaches

  • Middleware: Secure API routes by checking permissions before processing requests.
  • Route Guards: Prevent unauthorized navigation in frontend frameworks like Angular and Vue.
  • Higher-Order Components (HOCs): Wrap UI components to conditionally render content based on user permissions.
  • Direct Conditional Rendering: Use hasPermission inside components or templates to control visibility.

Framework-Specific Usage

Regardless of the framework, you can use hasPermission to implement access control efficiently. The following are some common usage patterns:

React

Use hasPermission inside components to conditionally render UI elements or wrap them in Higher-Order Components.

Angular

Implement hasPermission in route guards to restrict navigation or use directives for conditional rendering.

Vue.js

Utilize hasPermission in computed properties or within Vue directives like v-if to control access dynamically.

Svelte

Leverage hasPermission inside templates to show or hide elements based on user roles.

Backend Frameworks (Node.js)

Apply hasPermission in API endpoints, middleware, or controller logic to restrict access based on user roles.