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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
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
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews