LiveView hooks for handling authentication and authorization.
These hooks automatically catch authorization errors and handle them gracefully by redirecting users with friendly flash messages instead of showing 500 errors.
Usage
Wrap your mount function with handle_mount_errors:
def mount(params, session, socket) do
handle_mount_errors do
authorize!(socket, "some.permission")
# ... rest of mount logic
{:ok, socket}
end
end
Summary
Functions
Wraps mount logic to automatically catch and handle authorization errors.