edgars
Can ash_authentication Strategy.Password be modified
Hi, I know this question fits specifically into the Ash Forum category, but unfortunately, I can’t open new topics there, maybe because my account is brand new.
I was trying to wrap my head around Ash and ash_authentication and got stuck with this thing for a week. I was hoping someone could guide me in the right direction.
I have my basic ash_authentication user resource and have added attribute :trust_level, which would need to be set internally:
attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
attribute :trust_level, :integer, allow_nil?: false
end
I’m using the default setup with AshAuthentication.Strategy.Password to get the password registration working:
strategies do
password :password do
identity_field :email
confirmation_required?(false)
register_action_accept([:username, :trust_level])
resettable do
sender Testcourse.Accounts.User.Senders.SendPasswordResetEmail
end
end
end
I know I could set the :trust_level attribute by creating a new create action and using change set_attribute(:trust_level, get_trust_level), but I’m hesitant to create a new create action to create new users because AshAuthentication.Strategy.Password already provides the action register_with_password.
My question is, is it possible to add set_attribute(:trust_level, get_trust_level) to the already existent register_with_password action, or achieve a similar outcome another way? I found that there is a callback function transform in the AshAuthentication.Strategy.Password module, but I wasn’t able to understand how it works or how I could use it. I’m very new to the Elixir and Ash framework, and I’m still getting my head around the basics.
Thanks for any help.
Marked As Solved
zachdaniel
Yes, you can do this using the global changes block, which applies a change to all actions (except :destroy actions by default)
changes do
change SetTrustLevel, where: [action_is(:register_with_password)]
end
Also Liked
edgars
Thank you Zach for the quick response, that was exactly what I was looking for.
kurmetaubanov
Thank you Zach and edgars for your question, this is exactly what I was looking for too!
kokolegorille
Hello and welcome, I changed the category topic as requested
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









