From a265b573d4b6f693a30f17ccb830029a1d23f53f Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 12 Dec 2024 10:44:05 -0500 Subject: [PATCH] improvement: provide better error message on hijack protection --- .../tasks/ash_authentication_phoenix.install.ex | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/mix/tasks/ash_authentication_phoenix.install.ex b/lib/mix/tasks/ash_authentication_phoenix.install.ex index e7b0fc0..77803e6 100644 --- a/lib/mix/tasks/ash_authentication_phoenix.install.ex +++ b/lib/mix/tasks/ash_authentication_phoenix.install.ex @@ -271,7 +271,21 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.Install do |> redirect(to: return_to) end - def failure(conn, _activity, _reason) do + def failure(conn, activity, reason) do + message = + case {activity, reason} do + {{:magic_link, _}, + %AshAuthentication.Errors.AuthenticationFailed{ + caused_by: %Ash.Error.Forbidden{ + errors: [%AshAuthentication.Errors.CannotConfirmUnconfirmedUser{}] + } + }} -> + "You have already signed in another way, but have not confirmed your account. Please confirm your account." + + _ -> + "Incorrect email or password" + end + conn |> put_flash(:error, "Incorrect email or password") |> redirect(to: ~p"/sign-in")