AshMultiAccount.Phoenix.Components (AshMultiAccount v0.1.1)

Copy Markdown View Source

Slot-based account switcher component for multi-account UIs.

Provides data and URLs to consumer-supplied slots — no styling or HTML structure is imposed. The consumer controls all rendering.

Requirements

The current_user struct must belong to a resource with the AshMultiAccount extension applied. The primary_user (when provided) should be loaded via the get_user_with_linked_accounts action so linked account data is available.

Usage

<AshMultiAccount.Phoenix.Components.account_switcher
  current_user={@current_user}
  primary_user={@primary_user}
>
  <:account :let={account}>
    <.link :if={!account.current?} href={account.switch_url}>
      {account.user.name}
    </.link>
    <span :if={account.current?}>
      {account.user.name} (current)
    </span>
  </:account>

  <:add_account :let={url}>
    <.link href={url}>Add another account</.link>
  </:add_account>
</AshMultiAccount.Phoenix.Components.account_switcher>

Attributes

  • current_user (required) — the currently active user struct
  • primary_user — the primary account owner struct, or nil in standard mode
  • switch_path — base path for switch URLs (default: "/link/switch_to")
  • sign_in_path — sign-in path for add-account URL (default: "/sign-in")
  • link_path — link path for add-account URL (default: "/link/p")

Slot Data

Each :account slot receives a map with:

  • user — the user struct
  • current? — whether this is the currently active user
  • primary? — whether this is the primary account
  • switch_url — URL to switch to this account

The :add_account slot receives the URL to initiate linking a new account.

Summary

Types

Data passed to each :account slot via :let.

Types

account_entry()

@type account_entry() :: %{
  user: Ash.Resource.record(),
  current?: boolean(),
  primary?: boolean(),
  switch_url: String.t()
}

Data passed to each :account slot via :let.

Functions

account_switcher(assigns)

Attributes

  • current_user (:map) (required)
  • primary_user (:map) - Defaults to nil.
  • switch_path (:string) - Defaults to "/link/switch_to".
  • sign_in_path (:string) - Defaults to "/sign-in".
  • link_path (:string) - Defaults to "/link/p".

Slots

  • account - Rendered for each account. Receives account map via :let.
  • add_account - Rendered once with the add-account URL via :let.