Adding query string functionality to skip org setup.

This commit is contained in:
mike12345567 2021-07-21 18:23:49 +01:00
parent be1558e1e7
commit 63368fdae9
5 changed files with 32 additions and 9 deletions

View File

@ -18,6 +18,7 @@
onMount(async () => { onMount(async () => {
await admin.init() await admin.init()
auth.checkQueryString()
loaded = true loaded = true
}) })
</script> </script>

View File

@ -4,6 +4,7 @@
import { auth, admin } from "stores/portal" import { auth, admin } from "stores/portal"
import Logo from "assets/bb-emblem.svg" import Logo from "assets/bb-emblem.svg"
import { get } from "svelte/store" import { get } from "svelte/store"
import { onMount } from "svelte"
let tenantId = get(auth).tenantSet ? get(auth).tenantId : "" let tenantId = get(auth).tenantSet ? get(auth).tenantId : ""
@ -20,6 +21,10 @@
function handleKeydown(evt) { function handleKeydown(evt) {
if (evt.key === "Enter") setOrg() if (evt.key === "Enter") setOrg()
} }
onMount(() => {
auth.checkQueryString()
})
</script> </script>
<svelte:window on:keydown={handleKeydown} /> <svelte:window on:keydown={handleKeydown} />

View File

@ -2,13 +2,15 @@
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
import { auth } from "stores/portal" import { auth } from "stores/portal"
auth.checkQueryString()
$: { $: {
if (!$auth.user) { if (!$auth.user) {
$redirect("./auth") $redirect(`./auth`)
} else if ($auth.user.builder?.global) { } else if ($auth.user.builder?.global) {
$redirect("./portal") $redirect(`./portal}`)
} else { } else {
$redirect("./apps") $redirect(`./apps`)
} }
} }
</script> </script>

View File

@ -1,4 +1,8 @@
<script> <script>
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
$redirect("./builder") import { auth } from "../stores/portal"
auth.checkQueryString()
$redirect(`./builder`)
</script> </script>

View File

@ -47,14 +47,25 @@ export function createAuthStore() {
}) })
} }
function setOrganisation(tenantId) {
auth.update(store => {
store.tenantId = tenantId
store.tenantSet = !!tenantId
return store
})
}
return { return {
subscribe: store.subscribe, subscribe: store.subscribe,
checkQueryString: () => {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("tenantId")) {
const tenantId = urlParams.get("tenantId")
setOrganisation(tenantId)
}
},
setOrg: tenantId => { setOrg: tenantId => {
auth.update(store => { setOrganisation(tenantId)
store.tenantId = tenantId
store.tenantSet = !!tenantId
return store
})
}, },
checkAuth: async () => { checkAuth: async () => {
const response = await api.get("/api/admin/users/self") const response = await api.get("/api/admin/users/self")