nheingit
How to add multi-tenancy to users with an ash_authentication based app?
Hey everyone. I was trying to add multi tenancy (attribute-based) to my existing application that’s running ash_authentication.
To do this I needed to tie users to a new organizations resource upon account creation.
I wanted to hook into the existing register_with_password action since that’s already being used by some of my tests + the generated UI, but I wasn’t having much success in finding a way into the lifecycle of that action.
I tried overwriting the action in my resource by creating my own register_with_password field. But I quit getting errors upon compiling when I had just this bit of code:
create :register_with_password do
argument :password, :string, allow_nil?: false, sensitive?: true
argument :password_confirmation, :string, allow_nil?: false, sensitive?: true
change AshAuthentication.GenerateTokenChange
change AshAuthentication.Strategy.Password.HashPasswordChange
validate AshAuthentication.Strategy.Password.PasswordConfirmationValidation
end
From here looking at the HashPasswordChange documentation it looks like it should handle the hashing of the password, but if I try to use this new action, I get an error telling me that I’m missing the :hashed_password field in my changeset.
Was curious if anyone else had tried to do this and could point me in the right direction, or maybe I’m approaching the problem from the wrong angle?
Marked As Solved
zachdaniel
Try adding allow_nil_input [:hashed_password]? I believe in 3.0 that should not be necessary, but perhaps it is in 2.0, I don’t recall for sure ![]()
Also Liked
nheingit
That did the trick! thank you so much ![]()
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









