diff --git a/packages/builder/src/pages/builder/auth/index.svelte b/packages/builder/src/pages/builder/auth/index.svelte index 61c42ea089..daeb56cb6e 100644 --- a/packages/builder/src/pages/builder/auth/index.svelte +++ b/packages/builder/src/pages/builder/auth/index.svelte @@ -18,6 +18,7 @@ onMount(async () => { await admin.init() + auth.checkQueryString() loaded = true }) diff --git a/packages/builder/src/pages/builder/auth/org.svelte b/packages/builder/src/pages/builder/auth/org.svelte index 166935a135..caf31b2654 100644 --- a/packages/builder/src/pages/builder/auth/org.svelte +++ b/packages/builder/src/pages/builder/auth/org.svelte @@ -4,6 +4,7 @@ import { auth, admin } from "stores/portal" import Logo from "assets/bb-emblem.svg" import { get } from "svelte/store" + import { onMount } from "svelte" let tenantId = get(auth).tenantSet ? get(auth).tenantId : "" @@ -20,6 +21,10 @@ function handleKeydown(evt) { if (evt.key === "Enter") setOrg() } + + onMount(() => { + auth.checkQueryString() + }) diff --git a/packages/builder/src/pages/builder/index.svelte b/packages/builder/src/pages/builder/index.svelte index a90e1c7f2b..9638707169 100644 --- a/packages/builder/src/pages/builder/index.svelte +++ b/packages/builder/src/pages/builder/index.svelte @@ -2,13 +2,15 @@ import { redirect } from "@roxi/routify" import { auth } from "stores/portal" + auth.checkQueryString() + $: { if (!$auth.user) { - $redirect("./auth") + $redirect(`./auth`) } else if ($auth.user.builder?.global) { - $redirect("./portal") + $redirect(`./portal}`) } else { - $redirect("./apps") + $redirect(`./apps`) } } diff --git a/packages/builder/src/pages/index.svelte b/packages/builder/src/pages/index.svelte index 4c97b49763..0c083391ad 100644 --- a/packages/builder/src/pages/index.svelte +++ b/packages/builder/src/pages/index.svelte @@ -1,4 +1,8 @@ diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index fed8e9e1bd..17e9d11d3d 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -47,14 +47,25 @@ export function createAuthStore() { }) } + function setOrganisation(tenantId) { + auth.update(store => { + store.tenantId = tenantId + store.tenantSet = !!tenantId + return store + }) + } + return { subscribe: store.subscribe, + checkQueryString: () => { + const urlParams = new URLSearchParams(window.location.search) + if (urlParams.has("tenantId")) { + const tenantId = urlParams.get("tenantId") + setOrganisation(tenantId) + } + }, setOrg: tenantId => { - auth.update(store => { - store.tenantId = tenantId - store.tenantSet = !!tenantId - return store - }) + setOrganisation(tenantId) }, checkAuth: async () => { const response = await api.get("/api/admin/users/self")