Permit.Phoenix.LiveView.AuthorizeHook (permit_phoenix v0.4.0)

View Source

Hooks into the :mount and :handle_params lifecycles to authorize the current action. The current action is denoted by the :live_action assign (retrieved from the router), for example with the following route definition:

live "/organizations", OrganizationLive.Index, :index

the :live_action assign value will be :index.

Configuration

Add this module to the :on_mount option of the live_session in your router.

live_session :require_authenticated_user, on_mount: [
    {BlogWeb.UserAuth, :ensure_authenticated}, # authentication generated by mix phx.gen.auth
    Permit.Phoenix.LiveView.AuthorizeHook      # Permit.Phoenix's hook at mount
  ] do
  # Your live routes with named :live_action names
end

Usage

See Permit.Phoenix.LiveView for detailed information on authorizing LiveView navigation and events.