Skip to Content

← All archived runs

Run: role-switch-redirect

run.md

Run: role-switch-redirect

  • branch: claude/confident-tesla-2rqnev
  • pr: #504

01_define/output/spec.md

Spec: Redirect to the user's dashboard after a role/account switch

  • slug: role-switch-redirect
  • personas: Admin, CSM, SDM, Expert, Vendor, Customer
  • touches: apps/web (components/providers.tsx, components/sidebar/app-sidebar.tsx), apps/marketing (components/auth-provider.tsx, components/navigation.tsx)
  • complexity: standard

Problem

Clerk is configured for multi-session auth, so a user can hold several accounts/roles at once and switch between them from the Clerk UserButton. Today, switching sessions sends the user to the marketing site, which only offers a generic "Dashboard" button — an extra, confusing hop instead of landing them where they were heading. The cause is that neither ClerkProvider (apps/web/components/providers.tsx, apps/marketing/components/auth-provider.tsx) nor any UserButton sets Clerk's post-switch redirect URLs (afterSwitchSessionUrl, afterMultiSessionSingleSignOutUrl), so Clerk falls back to a default origin instead of the platform. This friction hits a core navigation flow for every persona, undermining the "Refine the Bridge" initiative's focus on dashboard usability and the small interaction details that keep users engaged (a contributor to the Q2 vendor active-engagement objective).

The platform already has everything needed to route correctly: ROLE_HOME in apps/web/lib/auth.ts maps each role to its dashboard, and the platform root (apps/web/app/page.tsx plus apps/web/proxy.ts) already detects the active session's role and forwards to that dashboard. The fix is to point Clerk's post-switch redirects at that role-aware root.

Proposed change

Configure Clerk's session-switch redirects so that switching account/role (or signing out of one of several active sessions) always lands the user on their correct dashboard, on both surfaces where a switch can occur:

  • Web platform (apps/web) — set the post-switch and multi-session single-sign-out redirects to the platform root /. The existing root route re-reads the now-active session's role and forwards to ROLE_HOME[role] (e.g. an expert lands on /expert, a vendor on /vendor), so the landing is role-aware for every persona and uses the single existing source of truth.
  • Marketing site (apps/marketing) — set the same post-switch / single-sign-out redirects so a switch from the marketing UserButton sends the user into the platform root (the platform then routes to the right dashboard) rather than leaving them on the marketing page. The "Dashboard" button continues to point into the platform root so it, too, resolves to the role dashboard.

No new routing logic is introduced — the change wires Clerk's redirect URLs to the role-aware platform root that already exists.

Acceptance criteria

  • A signed-in user with multiple sessions who switches account/role via the UserButton on the web platform lands directly on the newly-active role's dashboard (per ROLE_HOME), with no intermediate stop on the marketing site.
  • Switching account/role via the UserButton on the marketing site sends the user into the platform and resolves to the newly-active role's dashboard, not back to a marketing page.
  • Signing out of one account while other sessions remain active (multi-session single sign-out) lands the user on the remaining active session's dashboard, not the marketing site.
  • The landing dashboard is correct for each of the six roles (admin, csm, sdm, expert, vendor, customer), driven by the existing ROLE_HOME mapping rather than any hardcoded per-role path.
  • An expert with incomplete onboarding who switches into the expert role still follows the existing onboarding gate in apps/web/proxy.ts (the redirect lands on / and the middleware routes onward as it does today).

Out of scope

  • Adding or redesigning any explicit "switch role/account" UI (e.g. an OrganizationSwitcher) — this run only fixes where Clerk's existing switch flow redirects to.
  • Changing afterSignInUrl / afterSignOutUrl for the normal (non-switch) sign-in and sign-out flows, or the sign-in/sign-up pages' forceRedirectUrl handling.
  • Changing the role model, ROLE_HOME mappings, or middleware authorization rules.
  • The apps/dashboards mock app (standalone, mock-only — not part of the live auth flow).

Open questions

  • none

02_build/output/notes.md

Build notes: role-switch-redirect

  • commits: fix: role-switch-redirect — land on dashboard after session switch

What changed

The root cause was that Clerk's multi-session redirect URLs were never set, so switching account/role (or signing out of one of several sessions) fell back to a default that dropped the user on the marketing site. The fix wires those redirects to the role-aware platform root /, which the web app already resolves to the correct dashboard via ROLE_HOME (apps/web/lib/auth.ts, apps/web/app/page.tsx, apps/web/proxy.ts). No new routing logic was added.

  • apps/web/components/providers.tsx: set afterMultiSessionSingleSignOutUrl="/" on the web ClerkProvider — signing out of one session lands on the remaining session's role dashboard.
  • apps/web/components/sidebar/app-sidebar.tsx: set afterSwitchSessionUrl="/" on the sidebar UserButton — switching account/role lands on the newly-active role's dashboard.
  • apps/marketing/components/auth-provider.tsx: set afterMultiSessionSingleSignOutUrl="https://platform.sustentus.com/" on the marketing ClerkProvider — single sign-out routes into the platform, which resolves the dashboard.
  • apps/marketing/components/navigation.tsx: added a PLATFORM_URL constant; set afterSwitchSessionUrl={${PLATFORM_URL}/} on both (desktop + mobile) UserButtons; pointed the mobile "Dashboard" link at the platform root (it previously targeted /auth, which is not a real web route — (auth) is a route group, not a path segment).

Acceptance criteria status

  • Web platform UserButton switch lands on the newly-active role's dashboard — afterSwitchSessionUrl="/"/ resolves via ROLE_HOME, no marketing hop.
  • Marketing UserButton switch routes into the platform and resolves to the role dashboard — afterSwitchSessionUrl points at the platform root.
  • Multi-session single sign-out lands on the remaining session's dashboard — afterMultiSessionSingleSignOutUrl set on both ClerkProviders.
  • Correct for all six roles via ROLE_HOME — redirect target is / (role-aware), never a hardcoded per-role path.
  • Expert onboarding gate preserved — redirect lands on /, so apps/web/proxy.ts runs its existing onboarding routing unchanged.

Verify result

  • mechanical checks (format · lint · typecheck · build) run in CI + the Vercel preview, not here. No failures expected — the changes are additive props plus one local constant.

Notes for review

  • The redirect target is the role-aware root rather than any fixed dashboard, so multi-role users and every persona resolve correctly through the existing ROLE_HOME mapping.
  • Marketing redirects use the same hardcoded https://platform.sustentus.com origin already used by the nav's Dashboard links (no platform-URL env var exists in the repo).

03_release/output/changelog.md

Switch account or role and land straight on your dashboard

If you hold more than one account or role, switching between them now takes you straight to the right dashboard:

  • Switch account or role from your profile menu and you land directly on that role's dashboard — no detour through the marketing site.
  • Sign out of one account while another stays signed in, and you land on the remaining account's dashboard.
  • Whichever role you switch into — admin, CSM, SDM, expert, vendor, or customer — you arrive on its own dashboard.

Live entry: apps/help/app/changelog/2026-06-22-role-switch-redirect/page.mdx

03_release/output/investor-update.md

Account switching now lands users on the right dashboard

Who it's for: all six roles — admin, CSM, SDM, expert, vendor, customer What shipped: switching account or role now takes you straight to that role's dashboard, instead of detouring through the marketing site. Why it matters: Refine the Bridge — removing the small friction in everyday navigation that keeps multi-role users engaged.

Multi-session sign-out and all six role dashboards now route correctly.

Dig deeper: <merged-PR URL> · <changelog entry URL>