# `PhoenixKitWeb.Actor`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v2.40.1/lib/phoenix_kit_web/actor.ex#L1)

Who is acting, read from a LiveView socket, a `Plug.Conn` or an assigns
map — the one place modules ask, instead of each reading its own assign.

The admin `live_session` puts both `:phoenix_kit_current_scope` and
`:phoenix_kit_current_user` on the socket. The scope is the canonical
one (it is what permission checks read), so it wins; the bare user is
the fallback for callers that only have that — a test harness, a plain
controller. Modules used to pick one or the other, so the same action
could log an actor in one module and none in the next.

    PhoenixKit.Activity.log("crm", "crm.company_updated",
      PhoenixKitWeb.Actor.opts(socket) ++ [resource_uuid: company.uuid])

# `source`

```elixir
@type source() ::
  Phoenix.LiveView.Socket.t()
  | Plug.Conn.t()
  | PhoenixKit.Users.Auth.Scope.t()
  | map()
  | nil
```

Anything that knows who is acting.

# `opts`

```elixir
@spec opts(source()) :: keyword()
```

`[actor_uuid: uuid]` for a context call that logs, or `[]` when nobody
is signed in — so it can be appended to other options as is.

# `role`

```elixir
@spec role(source()) :: String.t() | nil
```

The name of the role the user is acting as (not PII), or `nil` — for
audit metadata that wants to say which role acted. With the role
switcher on, that is the active role, not the always-on roles that ride
along with it; otherwise the first role held.

# `uuid`

```elixir
@spec uuid(source()) :: String.t() | nil
```

The acting user's uuid, or `nil` when nobody is signed in.

    PhoenixKitWeb.Actor.uuid(socket)
    PhoenixKitWeb.Actor.uuid(conn)
    PhoenixKitWeb.Actor.uuid(scope)
    PhoenixKitWeb.Actor.uuid(%{phoenix_kit_current_user: user})

---

*Consult [api-reference.md](api-reference.md) for complete listing*
