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.ReplayAuthorizationThe 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
endActions and subjects:
:list— aPhoenixReplay.Recording.Summaryshown in the index:view— aPhoenixReplay.Recordingopened for replay:delete— aPhoenixReplay.Recording.SummaryorPhoenixReplay.Recording:clear—nil, deleting every recording
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
@type action() :: :list | :view | :delete | :clear
@type subject() :: PhoenixReplay.Recording.t() | PhoenixReplay.Recording.Summary.t() | nil
Callbacks
@callback authorize(action(), subject(), Phoenix.LiveView.Socket.t()) :: boolean()
Functions
@spec allowed?(module() | nil, action(), subject(), Phoenix.LiveView.Socket.t()) :: boolean()
Calls module.authorize/3, allowing everything when module is nil.