Customizing AshAuthentication.Phoenix

According to https://hexdocs.pm/ash_authentication_phoenix/AshAuthentication.Phoenix.html there are several ways to customise the authentication process: 1. Use the generic sign-in liveview - AshAuthentication.Phoenix.SignInLive.Apply 2. overrides using AshAuthentication.Phoenix.Overrides to set your own CSS classes for all components. 3. Build your own sign-in pages using the pre-defined components. 4. Build your own sign-in pages using the generated auth routes. Are there any examples, especially for 3 and 4? Do I even need AshAuthentication.Phoenix in these cases? Furthermore, out of curiosity, am I able to use the standard phx.gen.auth from phoenix and point to an ash resource instead of an ecto schema?
5 Replies
ZachDaniel
ZachDaniel3y ago
There aren't any examples provided by us for 3/4 (I'm not sure 4 is possible) That may be something that should be removed. Will have to ask @jart You can use phx.gen.auth, yes. But you will need to rewrite a fair amount of code from its ecto equivalent to its Ash equivalent.
Christoph
ChristophOP3y ago
Thanks for the quick reply. So, how would I build an own sign in page then? Could I solely require AshAuthentication then and do not need anything from AshAuthentication.Phoenix?
ZachDaniel
ZachDaniel3y ago
You will likely still want AshAuthenticationPhoenix to handle the actual sign in/authentication of users honestly Your best bet for implementing your own page currently is to look at the liveviews defined by ash_authentication_phoenix and copy them into your own thing
Christoph
ChristophOP3y ago
Alright, I will check the code to get a better understanding here. Just saw
defmacro sign_in_route(opts \\ []) do
{path, opts} = Keyword.pop(opts, :path, "/sign-in")
{live_view, opts} = Keyword.pop(opts, :live_view, AshAuthentication.Phoenix.SignInLive)
{as, opts} = Keyword.pop(opts, :as, :auth)
{otp_app, opts} = Keyword.pop(opts, :otp_app)
{layout, opts} = Keyword.pop(opts, :layout)
{on_mount, opts} = Keyword.pop(opts, :on_mount)
defmacro sign_in_route(opts \\ []) do
{path, opts} = Keyword.pop(opts, :path, "/sign-in")
{live_view, opts} = Keyword.pop(opts, :live_view, AshAuthentication.Phoenix.SignInLive)
{as, opts} = Keyword.pop(opts, :as, :auth)
{otp_app, opts} = Keyword.pop(opts, :otp_app)
{layout, opts} = Keyword.pop(opts, :layout)
{on_mount, opts} = Keyword.pop(opts, :on_mount)
Which seems that I can provide my own live_view component
ZachDaniel
ZachDaniel3y ago
Ah, okay that makes sense So I guess you can use your own liveview that way 🙂

Did you find this page helpful?