I am however getting warnings in my logs saying I should use
set_tenant
set_tenant
:
[warning] Storing the tenant in conn assigns is deprecated. deps/ash/lib/ash/plug_helpers.ex:169: Ash.PlugHelpers.get_tenant/1
[warning] Storing the tenant in conn assigns is deprecated. deps/ash/lib/ash/plug_helpers.ex:169: Ash.PlugHelpers.get_tenant/1
So I updated how I set the tenant:
conn|> Ash.PlugHelpers.set_tenant(tenant_id)
conn|> Ash.PlugHelpers.set_tenant(tenant_id)
This then sets the tenant in the private fields as per the docs.
But how do i get that tenant_id in my liveview? Its not stored in the session and I dont have access to the connection.
Solution
ok I think we are going in the right direction, so the authcontroller code is called when you sign in, but then it redirects and there you get a new conn and the browser pipeline only loads the user from the session. You need another plug/controller that you put after load_from_session, where you put this code
tenant = if user.is_super_admin? do [tenant | _] = Cvs.Tenant.Tenant.read!(actor: user) tenant.id else user.primary_registration.tenant_id end conn |> Ash.PlugHelpers.set_tenant(tenant)
tenant = if user.is_super_admin? do [tenant | _] = Cvs.Tenant.Tenant.read!(actor: user) tenant.id else user.primary_registration.tenant_id end conn |> Ash.PlugHelpers.set_tenant(tenant)
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.