PhoenixReplay.Authorization behaviour (PhoenixReplay v0.6.2)

Copy Markdown View Source

Behaviour for deciding what a dashboard viewer may see and do.

Pass the module to the router macro:

phoenix_replay "/replay",
  on_mount: [{MyAppWeb.UserAuth, :ensure_admin}],
  authorize: MyApp.ReplayAuthorization

The callback receives the action, the subject and the dashboard socket, whose assigns include anything set by your own :on_mount hooks:

defmodule MyApp.ReplayAuthorization do
  @behaviour PhoenixReplay.Authorization

  @impl true
  def authorize(:clear, _subject, socket), do: socket.assigns.current_user.admin?
  def authorize(_action, _subject, socket), do: socket.assigns.current_user != nil
end

Actions and subjects:

Without an :authorize module every action is allowed, so protect the dashboard route with your router pipeline or :on_mount hooks.

Storage pages the recording list itself only without an :authorize module. With one, the dashboard reads every summary and checks :list for each, so its pages and counts show exactly what the viewer may see.

Summary

Functions

Calls module.authorize/3, allowing everything when module is nil.

Types

action()

@type action() :: :list | :view | :delete | :clear

subject()

Callbacks

authorize(action, subject, t)

@callback authorize(action(), subject(), Phoenix.LiveView.Socket.t()) :: boolean()

Functions

allowed?(module, action, subject, socket)

@spec allowed?(module() | nil, action(), subject(), Phoenix.LiveView.Socket.t()) ::
  boolean()

Calls module.authorize/3, allowing everything when module is nil.