Template
Learn how to define permissions using templates
Overview
Permix provides a template
method that allows you to define permissions in a separate location from where they are set up. This is useful for organizing permission definitions and reusing them across different parts of your application.
Templates are validated when they are created, ensuring your permission definitions are correct before runtime.
Basic Usage
The simplest way to use templates is to define static permissions:
Dynamic Templates
Templates can accept parameters to create dynamic permissions based on runtime values:
Type Safety
Templates maintain full type safety from your Permix instance definition:
Role-Based Example
Templates are particularly useful for role-based permission systems:
Standalone Templates
You can define permission templates outside of the Permix instance using the PermixRules
type. This is useful when you want to organize your permission logic in separate files:
This approach allows you to:
- Keep permission logic separate from your Permix instance
- Reuse permission templates across different parts of your application
- Maintain full type safety with your Permix definition