team-alembic / ash_authentication_phoenix

Drop-in authentication support for Phoenix apps using AshAuthentication.
MIT License
52 stars 23 forks source link

Add the ability to customize the registration form with custom fields #119

Open guglielmobartelloni opened 1 year ago

guglielmobartelloni commented 1 year ago

Just as the title says: implement a way to add additional field in the registration form

jimsynz commented 1 year ago

Hi @guglielmobartelloni.

Thanks for taking the time to provide feedback.

You're right that it's not possible to do this at the moment, however the generated :register_with_password action is set up to accept any extra attributes passed to it. I've been scratching my head trying to figure out how to do this without opening a can of worms (input types, accessibility, etc) and I haven't thought of anything yet. Keen for any feedback anyone has on how to do this. In the mean time the best solution is to roll your own registration screen.

zachdaniel commented 1 year ago

@jimsynz perhaps we should actually make the generated register_with_password action have an explicit accept list? The forms that we're building in ash_authentication_phoenix could be altered by the client to set other public writable attributes unless we either 1. put an explicit accept list or 2. do a Map.take/2 on the params in ash_authentication_phoenix before submitting them.

zachdaniel commented 1 year ago

Yeah, thinking about it, I think all of the ash_authentication actions should have an explicit accept list.

allenwyma commented 4 months ago

I got caught up in this. So we can override :register_with_password an this will be picked up by AAP (ash_authentication_phoenix)?

zachdaniel commented 4 months ago

It won't add additional fields to the view, no. The suggestion is to write your own registration live view or to push the gathering of additional fields to a step after sign up.

allenwyma commented 4 months ago

i saw there's an inner_block that can somehow be set, but it wasn't so clear. But, seems as though, like you said, it'd be easier to just do our own template:

How can i reuse the registration code? There's no default action there.

zachdaniel commented 4 months ago

There is a register_with_password action added to the user resource (IIRC that is what its called) You can poke around to see the action and its arguments with

Ash.Resource.Info.actions(Resource) |> Enum.map(&(&1.name)) # to get the action names, so you can confirm it

Ash.Resource.Info.action(Resource, :name) # to see the action definition