Threadline.OperatorSurface.Auth (Threadline v1.0.0)

Copy Markdown View Source

Uses host authorization callbacks to admit or halt Threadline operator LiveView mounts.

Summary

Types

An option read by the operator LiveView authorization hook.

String-keyed route parameters passed to an operator LiveView mount.

String- or atom-keyed session values passed to an operator LiveView mount.

An opaque host-defined value carried in the LiveView session.

Functions

Allows or halts an operator LiveView mount using the host authorization callback.

Types

on_mount_opt()

@type on_mount_opt() ::
  {:authorize_fn, function()}
  | {:scope_query_fn, function()}
  | Threadline.repo_opt()
  | {:schemas, %{optional(String.t() | atom()) => module()}}
  | {:theme, :dark | :light | :system | String.t()}
  | {:exports, boolean()}
  | {:export_authorize_fn, function()}
  | {:coverage_authorize_fn, function()}
  | {:policy_authorize_fn, function()}
  | {:evidence_authorize_fn, function()}

An option read by the operator LiveView authorization hook.

on_mount_params()

@type on_mount_params() :: %{optional(String.t()) => String.t()}

String-keyed route parameters passed to an operator LiveView mount.

on_mount_session()

@type on_mount_session() :: %{
  optional(String.t() | atom()) => on_mount_session_value()
}

String- or atom-keyed session values passed to an operator LiveView mount.

on_mount_session_value()

@type on_mount_session_value() ::
  atom()
  | number()
  | bitstring()
  | pid()
  | port()
  | reference()
  | function()
  | tuple()
  | maybe_improper_list(on_mount_session_value(), on_mount_session_value())
  | %{optional(on_mount_session_value()) => on_mount_session_value()}

An opaque host-defined value carried in the LiveView session.

Functions

on_mount(opts, params, session, socket)

Allows or halts an operator LiveView mount using the host authorization callback.

The callback receives the socket-shaped value and may return :ok, true, or {:ok, scope} to continue. Other results or callback exceptions halt the mount and redirect to /.

Mount options

  • :authorize_fn — function. Optional here; the router macro requires a secure pipeline, this callback, or explicit acknowledgement.
  • :scope_query_fn — function. Optional. Applies host-owned query scoping.
  • :repo — Ecto.Repo module. Optional. Assigned to the LiveView socket.
  • :schemas — map from host table names to Ecto schema modules. Optional.
  • :theme — :dark, :light, or :system. Defaults to :dark.
  • :exports — boolean. Defaults to true; enables or disables export affordances.
  • :export_authorize_fn — function. Optional. Applies export-specific authorization.
  • :coverage_authorize_fn — function. Optional. Defaults to deny access to coverage.
  • :policy_authorize_fn — function. Optional. Defaults to deny access to policy views.
  • :evidence_authorize_fn — function. Optional. Defaults to deny access to evidence.

Other mount options are consumed by the router macro or companion hooks.

Returns

  • {:cont, socket} — authorization allows the mount.
  • {:halt, socket} — authorization denies or errors; the socket is redirected.