From eb05639608dec2b33d04eb3a9ce226cfcdc8e5cb Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Fri, 27 Feb 2026 18:02:22 -0800 Subject: [PATCH] fix: use rspaceNavUrl for (you)rSpace CTA redirect + pass onSuccess callback The auto-provision redirect was hardcoding /${slug}/canvas which is a 404 (canvas module id is "rspace"). Now uses rspaceNavUrl() for correct subdomain/path routing. Also passes onSuccess to showAuthModal so auto-provision runs even when signing in from a non-demo space. Co-Authored-By: Claude Opus 4.6 --- shared/components/rstack-space-switcher.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shared/components/rstack-space-switcher.ts b/shared/components/rstack-space-switcher.ts index 353c332..f5817dc 100644 --- a/shared/components/rstack-space-switcher.ts +++ b/shared/components/rstack-space-switcher.ts @@ -9,7 +9,7 @@ * Passes auth token so the API returns private spaces the user can access. */ -import { isAuthenticated, getAccessToken, getUsername } from "./rstack-identity"; +import { isAuthenticated, getAccessToken } from "./rstack-identity"; import { rspaceNavUrl, getCurrentModule as getModule } from "../url-helpers"; interface SpaceInfo { @@ -264,7 +264,9 @@ export class RStackSpaceSwitcher extends HTMLElement { // Find on page and open auth modal const identity = document.querySelector("rstack-identity") as any; if (identity?.showAuthModal) { - identity.showAuthModal(); + identity.showAuthModal({ + onSuccess: () => this.#autoProvision(), + }); } } else { // Authenticated but no owned space — auto-provision @@ -275,9 +277,10 @@ export class RStackSpaceSwitcher extends HTMLElement { async #autoProvision() { const token = getAccessToken(); - const username = getUsername(); if (!token) return; + const moduleId = this.#getCurrentModule(); + try { const res = await fetch("/api/spaces/auto-provision", { method: "POST", @@ -288,13 +291,10 @@ export class RStackSpaceSwitcher extends HTMLElement { }); const data = await res.json(); if (data.slug) { - window.location.href = `/${data.slug}/canvas`; - } else if (username) { - window.location.href = `/${username}/canvas`; + window.location.href = rspaceNavUrl(data.slug, moduleId); } } catch { - // Fallback: redirect to username path - if (username) window.location.href = `/${username}/canvas`; + // Silently fail — autoResolveSpace in identity may still handle it } }