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.
|
* 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";
|
import { rspaceNavUrl, getCurrentModule as getModule } from "../url-helpers";
|
||||||
|
|
||||||
interface SpaceInfo {
|
interface SpaceInfo {
|
||||||
|
|
@ -264,7 +264,9 @@ 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
|
||||||
|
|
@ -275,9 +277,10 @@ 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",
|
||||||
|
|
@ -288,13 +291,10 @@ export class RStackSpaceSwitcher extends HTMLElement {
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.slug) {
|
if (data.slug) {
|
||||||
window.location.href = `/${data.slug}/canvas`;
|
window.location.href = rspaceNavUrl(data.slug, moduleId);
|
||||||
} else if (username) {
|
|
||||||
window.location.href = `/${username}/canvas`;
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Fallback: redirect to username path
|
// Silently fail — autoResolveSpace in identity may still handle it
|
||||||
if (username) window.location.href = `/${username}/canvas`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue