Provides link_account/2 and switch_to_account/2 controller actions for
multi-account linking and switching.
Usage
defmodule MyAppWeb.MultiAccountController do
use MyAppWeb, :controller
use AshMultiAccount.Phoenix.Controller,
user_resource: MyApp.Accounts.User
# Optionally override redirect paths:
# def after_link_path(_conn), do: "/"
# def after_switch_path(_conn), do: "/"
# def sign_in_path(_conn, primary_user_id), do: "/sign-in?return_to=/link/p/#{primary_user_id}"
# def sign_out_path(_conn), do: "/sign-out"
endOptions
user_resource(required) — the Ash resource module for users.
Actions
link_account(conn, %{"primary_user_id" => id})— links the current user to an existing primary account, or sets up the multi-account session for the primary user themselves. Redirects to sign-in if no user is authenticated. For cross-user linking, GET renders an auto-submitting form (preserving REST semantics after the auth redirect), and POST creates the LinkedAccount record.switch_to_account(conn, %{"user_id" => id})— switches the current session to a different linked user. Rotates the session ID viaconfigure_session(renew: true)to reduce session fixation risk.