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.
This commit is contained in:
Graham McIntire 2026-01-06 13:30:07 -06:00
parent 152c308b68
commit 7df6e8b3b4
No known key found for this signature in database

View file

@ -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.