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 () => {
await admin.init()
auth.checkQueryString()
loaded = true
})
</script>

View File

@ -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()
})
</script>
<svelte:window on:keydown={handleKeydown} />

View File

@ -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`)
}
}
</script>

View File

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