AshPhoenix.LiveView.SubdomainHook (ash_phoenix v2.3.0)

View Source

This is a basic hook that loads the current tenant assign from a given value set on subdomain.

Options:

  • :assign (atom/0) - The key to use when assigning the current tenant The default value is :current_tenant.

  • :handle_subdomain - An mfa to call with the socket and a subdomain value. Can be used to do something like fetch the current user given the tenant.

        Must return either `{:cont, socket}`, `{:cont, socket, opts} or `{:halt, socket}`.

    To use the hook, you can do one of the following:

    live_session :foo, on_mount: [
    AshPhoenix.LiveView.SubdomainHook,
    ]

    This will assign the tenant's subdomain value to :current_tenant key by default.

    If you want to specify the assign key

    live_session :foo, on_mount: [
    {AshPhoenix.LiveView.SubdomainHook, [assign: :different_assign_key}]
    ]

    You can also provide handle_subdomain module, function, arguments tuple that will be run after the tenant is assigned.

    live_session :foo, on_mount: [
    {AshPhoenix.LiveView.SubdomainHook, [handle_subdomain: {FooApp.SubdomainHandler, :handle_subdomain, [:bar]}]
    ]

    This can be any module, function, and list of arguments as it uses Elixir's apply/3.

    The socket and tenant will be the first two arguments.

    The function return must match Phoenix LiveView's on_mount/1

    defmodule FooApp.SubdomainHandler do
    def handle_subdomain(socket, tenant, :bar) do
      # your logic here
      {:cont, socket}
    end
    end

Summary

Functions

on_mount(opts, params, session, socket)