Compare commits

..

No commits in common. "c4ebecf5df4c987ef6f9ee3c828a9c47ffc595e0" and "6f4befdd19d5f3171da42e07547f628ad9863f5b" have entirely different histories.

1 changed files with 8 additions and 8 deletions

View File

@ -9,7 +9,7 @@
* Passes auth token so the API returns private spaces the user can access. * Passes auth token so the API returns private spaces the user can access.
*/ */
import { isAuthenticated, getAccessToken } from "./rstack-identity"; import { isAuthenticated, getAccessToken, getUsername } from "./rstack-identity";
import { rspaceNavUrl, getCurrentModule as getModule } from "../url-helpers"; import { rspaceNavUrl, getCurrentModule as getModule } from "../url-helpers";
interface SpaceInfo { interface SpaceInfo {
@ -264,9 +264,7 @@ export class RStackSpaceSwitcher extends HTMLElement {
// Find <rstack-identity> on page and open auth modal // Find <rstack-identity> on page and open auth modal
const identity = document.querySelector("rstack-identity") as any; const identity = document.querySelector("rstack-identity") as any;
if (identity?.showAuthModal) { if (identity?.showAuthModal) {
identity.showAuthModal({ identity.showAuthModal();
onSuccess: () => this.#autoProvision(),
});
} }
} else { } else {
// Authenticated but no owned space — auto-provision // Authenticated but no owned space — auto-provision
@ -277,10 +275,9 @@ export class RStackSpaceSwitcher extends HTMLElement {
async #autoProvision() { async #autoProvision() {
const token = getAccessToken(); const token = getAccessToken();
const username = getUsername();
if (!token) return; if (!token) return;
const moduleId = this.#getCurrentModule();
try { try {
const res = await fetch("/api/spaces/auto-provision", { const res = await fetch("/api/spaces/auto-provision", {
method: "POST", method: "POST",
@ -291,10 +288,13 @@ export class RStackSpaceSwitcher extends HTMLElement {
}); });
const data = await res.json(); const data = await res.json();
if (data.slug) { if (data.slug) {
window.location.href = rspaceNavUrl(data.slug, moduleId); window.location.href = `/${data.slug}/canvas`;
} else if (username) {
window.location.href = `/${username}/canvas`;
} }
} catch { } catch {
// Silently fail — autoResolveSpace in identity may still handle it // Fallback: redirect to username path
if (username) window.location.href = `/${username}/canvas`;
} }
} }