Log in with username and password in Phoenix app
Does ash auth Phoenix have a declarative way to log in with username instead of email address? I changed my resources but it looks like I need to change something else.
7 Replies
I think there is a DSL option to specify this
Found 5 results in ash_authentication for query "username":
* AshAuthentication.Strategy.Password: https://ash-hq.org/docs/module/ash_authentication/3.9.6/ashauthentication-strategy-password
* AshAuthentication.Strategy.MagicLink: https://ash-hq.org/docs/module/ash_authentication/3.9.6/ashauthentication-strategy-magiclink
* AshAuthentication: https://ash-hq.org/docs/module/ash_authentication/3.9.6/ashauthentication
* Authentication: https://ash-hq.org/docs/dsl/ash_authentication/3.9.6/authentication
* Getting Started With Authentication: https://ash-hq.org/docs/guides/ash_authentication/3.9.6/tutorials/getting-started-with-authentication
That top guide shows
identity_field :email
Using " identity_field(:username)" does what I want. However, is there a way to require email address and username in the registration form? I tried
But it will prompt for one or the other.
Yeah, IIRC the autogenerated UI won’t add additional fields.
The general idea is to make it a two step process, like redirect them to a username screen.
PRs welcome WRT adding additional fields automatically
This article shows how to replace the sign in and register routes with your own custom liveviews, which is probably a great way to go to add your custom fields during registration: https://alembic.com.au/blog/customising-ash-authentication-with-phoenix-liveview
Alembic
Customising Ash Authentication with Phoenix LiveView
A Sydney-based Software Development Consultancy building cutting edge Web and API experiences with Elixir, TypeScript, GraphQL and React.
Thank you! I have been through that article. Very well written. I’d love to be able to give you some code back that would have a flow that say would verify the email address first and then ask for a username. My liveview and elixir skills are still pretty bad.
Currently toying with idea that email address isn’t unique. Only usernames in a tenant are unique
And why is email special? It could be a phone number.