Sigra.LiveView.OrganizationScope (Sigra v1.20.0)

Copy Markdown View Source

LiveView on_mount parallel of Sigra.Plug.LoadOrganizationFromSlug (Phase 16 D-03, D-04).

Rebinds socket.assigns.current_scope.active_organization and .membership from the :org URL param for the scoped route. The on_mount path is READ-ONLY with respect to the Plug session — it never calls put_session/2 (it has no Plug.Conn). The plug counterpart owns all session writes.

Behavior:

  • Unauthenticated socket (scope.user == nil): halts with {:halt, redirect(socket, to: login_path)}.
  • Missing org or not-a-member: halts by raising Phoenix.Router.NoRouteError so the router renders a 404 page (D-04 enumeration prevention — no distinction between unknown slug and not-a-member).

Usage

Inside a live_session:

on_mount {Sigra.LiveView.OrganizationScope, organizations: MyApp.Organizations, scope_module: MyApp.Scope}

Params forwarded to on_mount/4

  • :organizations — required. The host's use Sigra.Organizations module exposing __sigra_org_config__/0.
  • :scope_module — required. Host scope module implementing put_active_organization/3 (D-15).
  • :login_path — optional. Default: "/users/log_in".

Summary

Functions

on_mount(opts, params, session, socket)

on_mount callback. See Phoenix.LiveView.on_mount/1.