From 7df6e8b3b4884e075bdb126a35c377b0365db49f Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 6 Jan 2026 13:30:07 -0600 Subject: [PATCH] Redirect users to default org equipment page on login Changed signed_in_path to redirect users to their default organization's equipment page instead of the organization list. Behavior: - If user has organizations, redirect to first org's equipment page - First org is determined by most recently joined (membership.inserted_at) - If user has no organizations, redirect to /orgs to create one This provides a better UX by landing users directly at their equipment list instead of requiring an extra click through the org selector. --- lib/towerops_web/user_auth.ex | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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.