1
0
Fork 0
mirror of synced 2024-06-14 08:24:48 +12:00

Fixing issues with pages reloading in weird ways.

This commit is contained in:
mike12345567 2021-07-30 20:39:42 +01:00
parent 6c6ca18f98
commit 5e89cf5fa8
7 changed files with 32 additions and 19 deletions

View file

@ -4,6 +4,7 @@
import { onMount } from "svelte"
let loaded = false
$: multiTenancyEnabled = $admin.multiTenancy
$: hasAdminUser = !!$admin?.checklist?.adminUser
$: tenantSet = $auth.tenantSet
@ -14,12 +15,14 @@
loaded = true
})
// Force creation of an admin user if one doesn't exist
$: {
const apiReady = $admin.loaded && $auth.loaded
// if tenant is not set go to it
if (loaded && apiReady && multiTenancyEnabled && !tenantSet) {
$redirect("./auth/org")
} else if (loaded && apiReady && !hasAdminUser) {
}
// Force creation of an admin user if one doesn't exist
else if (loaded && apiReady && !hasAdminUser) {
$redirect("./admin")
}
}

View file

@ -36,11 +36,6 @@
notifications.error(`Failed to create admin user`)
}
}
function changeOrg() {
auth.setOrg(null)
$goto("../auth")
}
</script>
<section>
@ -62,7 +57,10 @@
Create super admin user
</Button>
{#if multiTenancyEnabled}
<ActionButton quiet on:click={changeOrg}>
<ActionButton quiet on:click={() => {
admin.unload()
$goto("../auth/org")
}}>
Change organisation
</ActionButton>
{/if}

View file

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

View file

@ -84,7 +84,10 @@
Forgot password?
</ActionButton>
{#if multiTenancyEnabled}
<ActionButton quiet on:click={() => $goto("./org")}>
<ActionButton quiet on:click={() => {
admin.unload()
$goto("./org")
}}>
Change organisation
</ActionButton>
{/if}

View file

@ -13,7 +13,7 @@
if (tenantId == null || tenantId === "") {
tenantId = "default"
}
auth.setOrg(tenantId)
await auth.setOrg(tenantId)
// re-init now org selected
await admin.init()
$goto("../")
@ -23,8 +23,8 @@
if (evt.key === "Enter") setOrg()
}
onMount(() => {
auth.checkQueryString()
onMount(async () => {
await auth.checkQueryString()
if (!multiTenancyEnabled) {
$goto("../")
} else {

View file

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

View file

@ -1,5 +1,6 @@
import { derived, writable, get } from "svelte/store"
import api from "../../builderStore/api"
import { admin } from "stores/portal"
export function createAuthStore() {
const auth = writable({
@ -50,25 +51,30 @@ export function createAuthStore() {
})
}
function setOrganisation(tenantId) {
async function setOrganisation(tenantId) {
const prevId = get(store).tenantId
auth.update(store => {
store.tenantId = tenantId
store.tenantSet = !!tenantId
return store
})
if (prevId !== tenantId) {
// re-init admin after setting org
await admin.init()
}
}
return {
subscribe: store.subscribe,
checkQueryString: () => {
checkQueryString: async () => {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("tenantId")) {
const tenantId = urlParams.get("tenantId")
setOrganisation(tenantId)
await setOrganisation(tenantId)
}
},
setOrg: tenantId => {
setOrganisation(tenantId)
setOrg: async tenantId => {
await setOrganisation(tenantId)
},
checkAuth: async () => {
const response = await api.get("/api/global/users/self")