lardcanoe

lardcanoe

I’ve been needing to customize our sign in, register, reset password, and forgot password pages for months. Every time I took a look at the ash_authentication_phoenix pages/code I ran away crying. And blog posts like Customising Ash Authentication with Phoenix LiveView did not make it seem easier.

After taking the plunge last night (due to yet another confused customer), I hooked up a custom Forgot Password page… and it all clicked.

We’re just doing POST calls to a few auth endpoints. Duh!

mix phx.routes

auth_path  *     /auth/user/password/register           MyAppWeb.AuthController {:user, :password, :register}
auth_path  *     /auth/user/password/sign_in            MyAppWeb.AuthController {:user, :password, :sign_in}
auth_path  *     /auth/user/password/reset_request      MyAppWeb.AuthController {:user, :password, :reset_request}
auth_path  *     /auth/user/password/reset              MyAppWeb.AuthController {:user, :password, :reset}

With that in mind, everything else made sense. The blogs, the docs, the other posts in this forum.

In iex, run AshAuthentication.Info.strategy!(MyApp.Accounts.User, :password) and things get even more clear, because so much of what seems like cryptic code was just there because literally every thing about ash_auth can be customized. So there is a ton of code to just deal with that. Especially since you can have numerous strategies enabled, and they deal with that. But I have just password and Google, so I can get really simple.

%AshAuthentication.Strategy.Password{
  confirmation_required?: true,
  hash_provider: AshAuthentication.BcryptProvider,
  hashed_password_field: :hashed_password,
  identity_field: :email,
  name: :password,
  password_confirmation_field: :password_confirmation,
  password_field: :password,
  provider: :password,
  register_action_accept: [],
  register_action_name: :register_with_password,
  registration_enabled?: true,
  resettable: %AshAuthentication.Strategy.Password.Resettable{
    token_lifetime: {3, :days},
    request_password_reset_action_name: :request_password_reset_with_password,
    password_reset_action_name: :password_reset_with_password,
    sender: {MyApp.Mailer.SendPasswordResetEmail, []}
  },
  resource: MyApp.Accounts.User,
  sign_in_action_name: :sign_in_with_password,
  sign_in_enabled?: true,
  sign_in_token_lifetime: {60, :seconds},
  sign_in_tokens_enabled?: false,
  sign_in_with_token_action_name: :sign_in_with_token_for_password,
  strategy_module: AshAuthentication.Strategy.Password
}

So when I see something similar to:

    api = AshAuthentication.Info.authentication_domain!(strategy.resource)
    subject_name = AshAuthentication.Info.authentication_subject_name!(strategy.resource)

    AshPhoenix.Form.for_action(strategy.resource, strategy.resettable.request_password_reset_action_name,
      api: api,
      as: to_string(subject_name),
      context: Ash.Helpers.deep_merge_maps(%{}, %{strategy: strategy, private: %{ash_authentication?: true}})
    )

I now realize those were (obviously) just normal forms that I’ve been working with in Ash for over a year. Again, duh!

Heck, you don’t even need any of that. You can make a basic sign in page with static html, similar to:

<form action="/auth/user/password/sign_in" method="POST">
  <input name="user[email]"/>
  <input type="password" name="user[password]"/>
  <button type="submit">Sign In</button>
</form>

(I’m just typing that out, it’s not real, missing CSRF for instance)

So don’t be afraid to write your custom auth pages. You can start with simple HTML!

I have no questions. Just hoping this post saves someone else a few hours.

My router.ex looks like:

    live_session :auth_sign_in do
      live "/sign-in", Live.Auth.SignIn, :sign_in
      live "/register", Live.Auth.Register, :register
      live "/reset", Live.Auth.ForgotPassword, :reset
    end

    auth_routes_for MyApp.Accounts.User, to: AuthController

    scope "/password-reset" do
      live_session :auth_reset do
        live "/:token", Live.Auth.ResetPassword, :reset
      end
    end

Some pages for reference:

https://github.com/team-alembic/ash_authentication/issues/497

Showing Posts 1 to 3

zachdaniel

zachdaniel

Creator of Ash

Love this! Thank you :heart:. In the near future we hope to have a basic generator to get people started with fully custom auth pages as well :slight_smile: Need to finish the fancy new ash authentication installers first though. But those are nearing the finish line.

tyfrankiv

tyfrankiv

helped a lot, thanks pal

parables

parables

Thank you for pointing out this.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews