Files
Mixer/lib/mixer/accounts/user/senders/send_magic_link_email.ex
2026-03-30 01:02:24 -04:00

41 lines
1.0 KiB
Elixir

defmodule Mixer.Accounts.User.Senders.SendMagicLinkEmail do
@moduledoc """
Sends a magic link email
"""
use AshAuthentication.Sender
use MixerWeb, :verified_routes
import Swoosh.Email
alias Mixer.Mailer
@impl true
def send(user_or_email, token, _) do
# if you get a user, its for a user that already exists.
# if you get an email, then the user does not yet exist.
email =
case user_or_email do
%{email: email} -> email
email -> email
end
new()
# TODO: Replace with your email
|> from({"noreply", "noreply@example.com"})
|> to(to_string(email))
|> subject("Your login link")
|> html_body(body(token: token, email: email))
|> Mailer.deliver!()
end
defp body(params) do
# NOTE: You may have to change this to match your magic link acceptance URL.
"""
<p>Hello, #{params[:email]}! Click this link to sign in:</p>
<p><a href="#{url(~p"/magic_link/#{params[:token]}")}">#{url(~p"/magic_link/#{params[:token]}")}</a></p>
"""
end
end