fix(auth): align desktop-login redirect with the request's loopback host
Fixes #44
Related to #27 / PR #28.
Bug
GET /api/auth/desktop-login sets a host-only session cookie scoped to
whichever host actually served the request, but always redirects to the
fixed localDashboardUrl (OPENSHIP_LOCAL_DASHBOARD_URL, default
http://localhost:<dashboardPort>) regardless of the request's own
host. When that fixed origin differs from the host the cookie was
minted against, the browser lands on the dashboard without the cookie
and bounces back to /login — this survives even the workaround
suggested in #27, since apps/dashboard/.../login/page.tsx already
derives the API URL correctly via getApiOrigin/alignLoopbackOrigin,
but the redirect back from desktopLogin was still fixed.
Fix
alignLoopbackOrigin (the loopback-hostname-alignment helper added for
#27 in apps/dashboard/src/lib/api/urls.ts) is moved into @repo/core
— already a shared dependency of both apps/api and apps/dashboard —
so desktopLogin can use the same logic server-side: align
localDashboardUrl's hostname with the incoming request's Host header
when both are loopback hostnames, instead of always trusting the fixed
env-configured URL. apps/dashboard's own copy is untouched (out of
scope for this fix, and it's already covered by its own test).
Verification
bun run --cwd packages/core lint and bun run --cwd apps/api lint
(both tsc --noEmit) pass clean.