Skip to content

Commit

Permalink
feat: Add action-specific flash messages to the generated AuthControl…
Browse files Browse the repository at this point in the history
…ler (#532)
  • Loading branch information
sevenseacat authored Nov 14, 2024
1 parent 4a43c23 commit 14a7df7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/mix/tasks/ash_authentication_phoenix.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,22 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.Install do
use #{inspect(Igniter.Libs.Phoenix.web_module(igniter))}, :controller
use AshAuthentication.Phoenix.Controller
def success(conn, _activity, user, _token) do
def success(conn, activity, user, _token) do
return_to = get_session(conn, :return_to) || ~p"/"
message =
case activity do
{:confirm_new_user, :confirm} -> "Your email address has now been confirmed"
{:password, :reset} -> "Your password has successfully been reset"
_ -> "You are now signed in"
end
conn
|> delete_session(:return_to)
|> store_in_session(user)
# If your resource has a different name, update the assign name here (i.e :current_admin)
|> assign(:current_user, user)
|> put_flash(:info, message)
|> redirect(to: return_to)
end
Expand All @@ -274,6 +282,7 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.Install do
conn
|> clear_session()
|> put_flash(:info, "You are now signed out")
|> redirect(to: return_to)
end
"""
Expand Down
11 changes: 10 additions & 1 deletion test/mix/tasks/ash_authentication_phoenix.install_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.InstallTest do
use TestWeb, :controller
use AshAuthentication.Phoenix.Controller
def success(conn, _activity, user, _token) do
def success(conn, activity, user, _token) do
return_to = get_session(conn, :return_to) || ~p"/"
message =
case activity do
{:confirm_new_user, :confirm} -> "Your email address has now been confirmed"
{:password, :reset} -> "Your password has successfully been reset"
_ -> "You are now signed in"
end
conn
|> delete_session(:return_to)
|> store_in_session(user)
# If your resource has a different name, update the assign name here (i.e :current_admin)
|> assign(:current_user, user)
|> put_flash(:info, message)
|> redirect(to: return_to)
end
Expand All @@ -109,6 +117,7 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.InstallTest do
conn
|> clear_session()
|> put_flash(:info, "You are now signed out")
|> redirect(to: return_to)
end
end
Expand Down

0 comments on commit 14a7df7

Please sign in to comment.