team-alembic / ash_authentication

The Ash Authentication framework
MIT License
92 stars 48 forks source link

Igniters could provide more fully-fleshed email sender modules #815

Open sevenseacat opened 1 day ago

sevenseacat commented 1 day ago

Igniters such as ash_authentication.add_strategy password generate sender modules that look like this:

defmodule Tunez.Accounts.User.Senders.SendPasswordResetEmail do
  @moduledoc """
  Sends a password reset email
  """

  use AshAuthentication.Sender
  use TunezWeb, :verified_routes

  @impl true
  def send(_user, token, _) do
    # Example of how you might send this email
    # Tunez.Accounts.Emails.send_password_reset_email(
    #   user,
    #   token
    # )

    IO.puts("""
    Click this link to reset your password:

    #{url(~p"/password-reset/#{token}")}
    """)
  end
end

It took me a bit to realize that to actually send the email, I would have to create the Tunez.Accounts.Emails module, and define that function with the right copy and then create and send an email.

My thinking was that the igniter could generate something more fully-featured, like the example in the tutorial - https://hexdocs.pm/ash_authentication/confirmation.html#confirming-newly-registered-users, eg.

zachdaniel commented 13 hours ago

So, we can do this, but to do it right we likely need to add a couple swoosh specific helpers, i.e Igniter.Libs.Swoosh. Eventually we'd like these to be extracted out to their respective libraries.

zachdaniel commented 13 hours ago

@sevenseacat I imagine you'd like this in for the auth chapter in the book. It also makes sense from our live stream today with Peter who expected to go to the dev mailbox and see the email right away. We ought to be able to set it up without too much hassle.

zachdaniel commented 13 hours ago

I'll try and do this tomorrow, but it might have to wait til next week.

sevenseacat commented 9 hours ago

Yes I did the exact same thing as Peter; when I saw the output in my logs I expected to also see it in an email in the dev mailbox.

Maybe it doesn't have to go that far, but having the Emails module set up ready to plug a mailer straight into would be a good compromise.