Pow API email confirmation doesn't update "email_confirmed_at"

I followed this guide: notebook-pub/programming/phoenix/pow/adding-email-confirmation-to-an-api.md at master · mreishus/notebook-pub · GitHub

Everything seems to work and I get an email and upon clicking it the expected message:

{"success":{"message":"Email confirmed"}}

The only problem is that in DB, the user row isn’t updated. So there is still email_confirmation_token filled but email_confirmed_at stays NULL.

If I use this line manually(in console): PowEmailConfirmation.Ecto.Context.confirm_email(user, %{}, otp_app: :my_app) it works.

2021-01-07-101559_554x456_scrot

In the screen above, the last one was manually approved and the previous 2 were via link.

1 Like

I have a similar problem, still looking for a solution.

Pow needs no small amount of steps to set up properly inside a project. Without an example GitHub project that demonstrates the problem, it’s hard for anyone to try and help.

1 Like

Adding PowEmailConfirmation.Plug.confirm_email/2 to show/2 function in confirmation_controller.ex solved my issue.
I’ve followed your mentioned guide as well, which didn’t work. Then after reading around, I modified the show/2 function as following:

    case PowEmailConfirmation.Plug.load_user_by_token(conn, token) do
      {:error, conn} ->
        conn
        |> put_status(401)
        |> json(%{error: %{status: 401, message: "Invalid confirmation code"}})

      {:ok, conn} ->
        # Extra bit starting
        case PowEmailConfirmation.Plug.confirm_email(conn, %{}) do
          {:ok, _, conn} ->
            conn
            |> json(%{success: %{message: "Email confirmed"}})

          {:error, _, conn} ->
            conn
            |> put_status(401)
            |> json(%{error: %{status: 401, message: "Invalid confirmation code"}})
        end
        # Extra bit ending 
    end
  end