Hydration (SSR)
Learn how to hydrate and dehydrate permissions in your application
Overview
Hydration is the process of converting server-side state into client-side state. In Permix, hydration allows you to serialize permissions on the server and restore them partially on the client.
Note that function-based permissions will be converted to false
during dehydration since functions cannot be serialized to JSON. That's why you should call setup
method on the client side immediately after hydration.
Usage
Permix provides two methods for handling hydration:
dehydrate
- Converts the current permissions state into a JSON-serializable formathydrate
- Restores permissions from a previously dehydrated state
Server-Side Rendering
Hydration is particularly useful in server-side rendering scenarios where you want to transfer permissions from the server to the client: