daniglezl
AshAuthentication does not use tenant set with Ash.PlugHelpers.set_tenant
Hi, I’m trying to get AshAuthentication to work in a context multi-tenancy setup but I’m having trouble getting AshAuthentication to use the tenant set using Ash.PlugHelpers.set_tenant/2. I have the following plug added to the pipeline:
defmodule ExampleWeb.Plugs.TenantSetter do
@moduledoc """
Set Ash tenant from current_tenant in connection
"""
@behaviour Plug
@impl true
def init(opts), do: opts
@impl true
def call(conn, _opts) do
Ash.PlugHelpers.set_tenant(conn, conn.assigns.current_organization.id)
end
end
and I can see the tenant being added to conn but I get the following error when trying to authenticate:
[warning] Unhandled error in form submission for Example.Accounts.User.sign_in_with_password
This error was unhandled because Ash.Error.Invalid.TenantRequired does not implement the `AshPhoenix.FormData.Error` protocol.
** (Ash.Error.Invalid.TenantRequired) Queries against the Example.Accounts.User resource require a tenant to be specified
I’ve found other topics that mention that AshAuthentication should use the tenant when set with the PlugHelpers. Is this correct?
Marked As Solved
zachdaniel
Ah, I wonder if we didn’t back port a fix somewhere:( I’m not at a computer, but you could fork ash authentication phoenix, and check out the tag for the version you’re on, make a branch, and cherry pick this commit: fix: set tenant on form creation · team-alembic/ash_authentication_phoenix@7430ab7 · GitHub
Then you can point at your fork. That will likely fix the issue.
Or you can open an issue and well fix it in the next day or two ![]()
Also Liked
jclement
Success! That works for me now (the update, I mean). Thank you so much for all your help on this!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









