Can You Add Additional Attributes to ash_authentication_phoenix?

I went through the tutorial for and have password/email auth working. I'd like to add a role attribute to my user resource so I did the below:
attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
attribute :role, :atom do
constraints [one_of: [:admin, :user]]
default :user
allow_nil? false
end
end
attributes do
uuid_primary_key :id
attribute :email, :ci_string, allow_nil?: false
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true
attribute :role, :atom do
constraints [one_of: [:admin, :user]]
default :user
allow_nil? false
end
end
At runtime, the form seems to have errors like this:
ERROR: column u0.role does not exist at character 51
ERROR: column u0.role does not exist at character 51
Is the intent that I can have arbitrary attributes on a user resources used with Ash Authentication like this, or is there another approach I should be looking into? Ultimately, I'd like to add some code to seeds.exs which creates a couple :admin accounts and gate certain features behind only that role, but I'm very new to Ash, Phoenix and Elixir so I'm not sure if I'm heading in the right general direction or not.
4 Replies
dblack
dblack2y ago
Assuming you're using ash_postgres, have you run the migration generator since adding the role attribute? I think that error is postgres complaining that the table doesn't have a role column It's been a while since I used Ash Authentication, but I think yoiu should be able to add arbitrary attributes to your user resource as long as they are not required, or there are defaults for them. If you want to capture other information during registration (other than username/email and password) then you'll need to do that in a later stage, or create a custom registration liveview/controller.
mayl
mayl2y ago
I'm away from PC right now but I think you're right I overlooked needing to run the migrations. I'll give that a try and report back, thanks so much for the nudge in the right direction!
lpmay
lpmayOP2y ago
So can confirm, that did the trick! Thank you @dblack for the help!
dblack
dblack2y ago
No worries!

Did you find this page helpful?