PhoenixKit.Users.ScopeNotifier (phoenix_kit v1.6.16)

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 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_roles_updated(user_id)

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

Broadcasts a scope refresh notification for the given user.

subscribe(user_id)

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

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

unsubscribe(user_id)

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

Unsubscribes the current process from scope refresh notifications.