Instance
Learn how to create a new Permix instance
Overview
Instance is the main entry point for Permix that will check permissions in every returned method. To create an instance, you need to use the createPermix
function.
TypeScript
Permix is built with TypeScript, providing type safety and validation. Using TypeScript enables autocompletion and compile-time checks for your permission definitions.
Generic type
Permix instance accepts a generic type to define permissions.
action
Union type of all actions you want to check on the entity.
dataType
Not required, but recommended.
To define a type of your entities, you can pass the dataType
property to a generic type. This is useful if you want to check permissions on a specific entity otherwise the type will be unknown
.
PermixDefinition
You can use PermixDefinition
type to define your permissions separately from the instance.
Return type
Each Permix instance provides a list of methods to manage and check permissions. These methods are documented in detail on their separate pages.
JavaScript
Not using TypeScript? Permix works perfectly fine even with plain JavaScript.
Initial Rules
You can provide initial rules when creating a Permix instance. This allows you to set up permissions immediately without calling setup
separately.
This is equivalent to:
Initial rules are useful when you have permissions that are known at initialization time and don't need to be loaded asynchronously.
You still should pass generic type to createPermix
even if you provide initial rules. Otherwise, Permix will not be able to validate your permissions.