The e-mail confirmation works when signing up, but when the e-mail is changed the confirmation link is send to the old address instead of the new one.
It's due to how mails works. The mailer is recommended to be set up this way:
defmodule MyAppWeb.PowMailer do
use Pow.Phoenix.Mailer
require Logger
def cast(%{user: user, subject: subject, text: text, html: html, assigns: _assigns}) do
# Build email struct to be used in `process/1`
%{to: user.email, subject: subject, text: text, html: html}
end
def process(email) do
# Send email
Logger.debug("E-mail sent: #{inspect email}")
end
end
In the above, a user struct is passed in and the email is fetched from that user struct (so it'll always be user.email instead of user.unconfirmed_email).
I believe the simplest solution would be to change PowEmailConfirmation.Phoenix.ControllerCallbacks.send_confirmation_email/2 logic, so the user passed on to the mailer will have :email set to the value :unconfirmed_email.
So the email still goes to the old address. I replaced:
{:pow, "~> 1.0.12"}
with
{:pow, github: "danschultzer/pow", ref: "email-confirmation鈥潁
Then did a mix deps.get, followed by mix phx.server. Just in case, I did a mix clean/compile
~Apparently the fix is not merged into master yet.~
@volkerholloh Looks like @mitkins does use the right branch though.
I just tested it myself in my demo Phoenix app, and it does sends to the new e-mail now ([email protected]):
[debug] E-mail sent: %{
html: "<h3>Hi,</h3><p>Please use the following link to confirm your e-mail address:</p><p><a href=\"http://localhost:4000/confirm-email/9117602c-c2bd-4e5c-b355-f03ae3b0d06a\">http://localhost:4000/confirm-email/9117602c-c2bd-4e5c-b355-f03ae3b0d06a</a></p>",
subject: "Confirm your email address",
text: "Hi,\n\nPlease use the following link to confirm your e-mail address:\n\nhttp://localhost:4000/confirm-email/9117602c-c2bd-4e5c-b355-f03ae3b0d06a",
to: "[email protected]"}
Also, the above has an typo, it should be:
{:pow, github: "danschultzer/pow", ref: "email-confirmation"}
(and if you use PowAssent, then add override: true to it)
@mitkins I've cleaned up the PR and merged it in to master. You should be able to test it out with this now:
{:pow, github: "danschultzer/pow"}
Let me know if it works for you!
I see what I've done wrong. I had made a copy of PowEmailConfirmation.Phoenix.ControllerCallbacks.send_confirmation_email in my own RegistrationController - because I wanted control over the url/route that's embedded in the email.
It didn't have the newly revised unconfirmed_user map.
It's working now, thanks!