diff --git a/lib/towerops_web/user_auth.ex b/lib/towerops_web/user_auth.ex index a3fce358..81ee6a22 100644 --- a/lib/towerops_web/user_auth.ex +++ b/lib/towerops_web/user_auth.ex @@ -217,7 +217,24 @@ defmodule ToweropsWeb.UserAuth do end end - defp signed_in_path(_conn), do: ~p"/orgs" + defp signed_in_path(conn) do + user = conn.assigns[:current_scope] && conn.assigns.current_scope.user + + if user do + # Get user's organizations (ordered by most recently joined first) + case Towerops.Organizations.list_user_organizations(user.id) do + [first_org | _] -> + # Redirect to the first organization's equipment page + ~p"/orgs/#{first_org.slug}/equipment" + + [] -> + # No organizations yet, go to org list + ~p"/orgs" + end + else + ~p"/orgs" + end + end @doc """ Plug for routes that require the user to be authenticated.