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 <noreply@anthropic.com>
This commit is contained in:
parent
b32d752858
commit
eb05639608
|
|
@ -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 <rstack-identity> 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue