Setup
Learn how to setup permissions in your project
Overview
After creating Permix instance, you need to define permissions with setup
method. You can call setup
in any time with any permissions and Permix will replace the previous permissions.
You always should describe all permissions in the setup
method that was defined in the Permix generic type.
For role separation, you can use the template
method.
Object definition
You can also use enum
based permissions. See Enum-based for more information.
Type-Based
When creating a Permix instance, you can define entities that will be used in the setup
method for each related entity. This allows you to check permissions for specific data entities. So instead of boolean
you can use functions to check permissions.
unknown
If you cannot define entity types in the Permix instance, the types will be unknown
by default, but you can still define them later in the setup
method.
This approach is not recommended as it reduces type safety and IDE support.
Getting Rules
You can get the current rules from an existing Permix instance using the getRules
function:
The getRules
function returns the exact rules object that was set using setup
, including any permission functions.