PhoenixKitAI.Web.AuthHelpers (PhoenixKitAI v0.3.0)

Copy Markdown View Source

Per-LV actor-resolution helpers.

Every mutating context call in the AI admin LVs threads actor_uuid

  • actor_role through actor_opts(socket) so the activity feed attributes the change to the right user. This module is the single source for that shape — without it, four copies (endpoints.ex, endpoint_form.ex, prompts.ex, prompt_form.ex) drifted in parallel.

Summary

Functions

Builds the actor_opts keyword list expected by every mutating context fn (create_endpoint/2, update_endpoint/3, delete_endpoint/2, reorder_endpoints/2, create_prompt/2, update_prompt/3, etc).

Returns true when the socket's scope reports admin role, false otherwise (including nil scope).

Functions

actor_opts(socket)

@spec actor_opts(Phoenix.LiveView.Socket.t()) :: keyword()

Builds the actor_opts keyword list expected by every mutating context fn (create_endpoint/2, update_endpoint/3, delete_endpoint/2, reorder_endpoints/2, create_prompt/2, update_prompt/3, etc).

Returns [actor_uuid: uuid, actor_role: "admin" | "user"] when the socket carries a phoenix_kit_current_user with a uuid, or [actor_role: ...] only when no user is in the socket (rare — on_mount usually guarantees one, but defensive callers still want the role).

admin?(socket)

@spec admin?(Phoenix.LiveView.Socket.t()) :: boolean()

Returns true when the socket's scope reports admin role, false otherwise (including nil scope).