Ash FrameworkAF
Ash Framework5mo ago
3 replies
Yahya Oxley

Use of current_tenant throughout app

I am trying to build a multi tenant app and currently have things working placing this socket.assigns.current_tenant in every place where I am about to do a query

def mount(_params, _session, socket) do
    form =
      MyApp.Team.form_to_create_person(
        actor: socket.assigns.current_user,
        tenant: socket.assigns.current_tenant
      )
      |> AshPhoenix.Form.ensure_can_submit!()

    socket =
      socket
      |> assign(:form, to_form(form))
      |> assign(:page_title, "New Person")
      |> assign(:role_options, role_options())

    {:ok, socket}
  end


I was wondering if there is a better way.. maybe a way to have all queries include socket.assigns.current_user as the tenant instead of manually putting it everywhere. Not sure if I am making sense! :p
Solution
It makes sense but we don't do it that way on purpose. It can have strange side effects to do magical things like that.
Was this page helpful?