diff --git a/apps/app/src/App.tsx b/apps/app/src/App.tsx index 5e0e0586..9f1ad14a 100644 --- a/apps/app/src/App.tsx +++ b/apps/app/src/App.tsx @@ -221,6 +221,16 @@ function RoutePending() { * Shared with ConnectMcp.tsx (kept as a literal there to avoid a circular import). */ const MCP_CONNECT_STORAGE_KEY = 'memwal_mcp_connect' +function parsePendingMcpConnectPath(pending: string) { + try { + const params = JSON.parse(pending) as Record + const qs = new URLSearchParams(params).toString() + return qs ? `/connect/mcp?${qs}` : null + } catch { + return null + } +} + /** Lands here after a successful sign-in (the OAuth redirect_uri is the app * root). If a /connect/mcp flow was interrupted by that redirect, resume it * by restoring the saved query string; otherwise go to the dashboard. */ @@ -229,11 +239,8 @@ function PostAuthRedirect() { if (pending) { // Consume once — prevents a redirect loop on later visits to `/`. sessionStorage.removeItem(MCP_CONNECT_STORAGE_KEY) - try { - const params = JSON.parse(pending) as Record - const qs = new URLSearchParams(params).toString() - if (qs) return - } catch { /* fall through to dashboard */ } + const resumePath = parsePendingMcpConnectPath(pending) + if (resumePath) return } return }