Ash Multi Account

CILicense: MITHex version badgeHexdocs badge

Multi-account linking and switching for Phoenix apps using Ash and AshAuthentication. Let users add multiple accounts and switch between them without re-authenticating — similar to Google/Apple's account switcher UX.

Why?

AshAuthentication and AshAuthentication.Phoenix provide excellent single-user authentication — strategies, session management, and LiveView integration all work out of the box. But many apps need users to link and switch between multiple accounts: family accounts, work/personal separation, admin impersonation. That's a different problem entirely, requiring its own session management, security considerations (session fixation, authorization checks), and UI integration across both LiveView and controller-rendered pages.

Ash Multi Account picks up where AshAuthentication leaves off, adding multi-account linking and switching as a natural extension of the same Ash ecosystem.

Features

Built On

Ash Multi Account is an extension for the Ash Framework ecosystem.

Required — pulled in automatically as dependencies:

Also needed (not pulled in transitively):

Works with any Ash data layer (Postgres, SQLite, ETS, etc.) and any AshAuthentication strategy (password, OAuth, magic links, etc.).

Quick Look

Add two extensions to your resources — the transformer generates the full schema:

# User resource — add AshMultiAccount alongside AshAuthentication
defmodule MyApp.Accounts.User do
  use Ash.Resource,
    extensions: [AshAuthentication, AshMultiAccount]

  multi_account do
    linked_account_resource MyApp.Accounts.LinkedAccount
    active_check {:status, :active}
    display_fields [:name, :avatar_url]
    max_linked_accounts 5
  end
end

# LinkedAccount resource — attributes, relationships, and actions generated automatically
defmodule MyApp.Accounts.LinkedAccount do
  use Ash.Resource,
    extensions: [AshMultiAccount.LinkedAccount]

  multi_account do
    user_resource MyApp.Accounts.User
  end
end

The Phoenix integration provides plugs, controllers, router macros, and a LiveView hook — all resolving the same @current_user and @primary_user assigns. See the Getting Started guide for the full walkthrough.

Documentation

Demo App

A complete demo Phoenix app lives in example/demo/. It uses password authentication with ETS (no external dependencies — just mix setup && mix phx.server).

The demo includes two pages to demonstrate that multi-account works with both rendering approaches:

Both pages show the same user data, account switcher, and multi-account status — proving the library works identically in both contexts. Switch between them using the tabs at the top of each page.

See the demo README for setup instructions and a walkthrough.

Demo app showing the account switcher dropdown

Installation

# mix.exs
{:ash_multi_account, "~> 0.1.0"}

The recommended way to get started is with the Igniter installer, which automates resource setup, domain registration, controller creation, and router configuration:

mix igniter.install ash_multi_account

See the Getting Started guide for manual setup or additional options.

License

MIT — see LICENSE.


AshMultiAccount is an independent project by Chris Cox, not affiliated with or maintained by the Ash Framework team. Built as a contribution back to the Phoenix and Ash community that has given me so much.