From 30017b768447463e19c1b5e27ccf766b97f8f9e3 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sun, 12 Mar 2023 17:33:16 -0400 Subject: [PATCH] improvement: use tenant in ash_authentication_live_session (#160) --- lib/ash_authentication_phoenix/live_session.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ash_authentication_phoenix/live_session.ex b/lib/ash_authentication_phoenix/live_session.ex index bb15d0b..9f192b9 100644 --- a/lib/ash_authentication_phoenix/live_session.ex +++ b/lib/ash_authentication_phoenix/live_session.ex @@ -96,7 +96,7 @@ defmodule AshAuthentication.Phoenix.LiveSession do |> Enum.reduce(socket, fn {key, value}, socket -> with {:ok, resource} <- Map.fetch(resources, key), {:ok, user} <- - AshAuthentication.subject_to_user(value, resource), + AshAuthentication.subject_to_user(value, resource, tenant: session["tenant"]), {:ok, subject_name} <- Info.authentication_subject_name(resource) do assign(socket, String.to_existing_atom("current_#{subject_name}"), user) @@ -127,7 +127,9 @@ defmodule AshAuthentication.Phoenix.LiveSession do String.to_existing_atom("current_#{subject_name}") ) do {:ok, user} when is_struct(user, resource) -> - Map.put(session, subject_name, AshAuthentication.user_to_subject(user)) + session + |> Map.put(subject_name, AshAuthentication.user_to_subject(user)) + |> Map.put("tenant", Ash.PlugHelpers.get_tenant(conn)) _ -> session