PhoenixKit.Users.ScopeNotifier (phoenix_kit v2.26.0)

Copy Markdown View Source

Handles PubSub notifications for user scope refreshes.

When a user's roles change, we broadcast a message on a user-specific topic so any connected LiveViews can refresh their cached authentication scope without requiring a full reconnect.

Summary

Functions

Broadcasts that the user changed the role they act as (PhoenixKit.Users.ActiveRole). Refreshed exactly like broadcast_roles_updated/1; the extra element lets a page that the new role cannot reach say why it is sending the visitor away.

Broadcasts a scope refresh notification for the given user.

Subscribes the current process to scope refresh notifications for the user.

Unsubscribes the current process from scope refresh notifications.

Functions

broadcast_active_role_changed(user_uuid)

@spec broadcast_active_role_changed(PhoenixKit.Users.Auth.User.t() | binary() | nil) ::
  :ok

Broadcasts that the user changed the role they act as (PhoenixKit.Users.ActiveRole). Refreshed exactly like broadcast_roles_updated/1; the extra element lets a page that the new role cannot reach say why it is sending the visitor away.

broadcast_roles_updated(user_uuid)

@spec broadcast_roles_updated(PhoenixKit.Users.Auth.User.t() | binary() | nil) :: :ok

Broadcasts a scope refresh notification for the given user.

subscribe(user_uuid)

@spec subscribe(PhoenixKit.Users.Auth.User.t() | binary()) :: :ok | {:error, term()}

Subscribes the current process to scope refresh notifications for the user.

unsubscribe(user_uuid)

@spec unsubscribe(PhoenixKit.Users.Auth.User.t() | binary() | nil) :: :ok

Unsubscribes the current process from scope refresh notifications.