Fixing issues with pages reloading in weird ways.
This commit is contained in:
parent
61de20616f
commit
af9b0a738d
|
@ -4,6 +4,7 @@
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
let loaded = false
|
let loaded = false
|
||||||
|
|
||||||
$: multiTenancyEnabled = $admin.multiTenancy
|
$: multiTenancyEnabled = $admin.multiTenancy
|
||||||
$: hasAdminUser = !!$admin?.checklist?.adminUser
|
$: hasAdminUser = !!$admin?.checklist?.adminUser
|
||||||
$: tenantSet = $auth.tenantSet
|
$: tenantSet = $auth.tenantSet
|
||||||
|
@ -14,12 +15,14 @@
|
||||||
loaded = true
|
loaded = true
|
||||||
})
|
})
|
||||||
|
|
||||||
// Force creation of an admin user if one doesn't exist
|
|
||||||
$: {
|
$: {
|
||||||
const apiReady = $admin.loaded && $auth.loaded
|
const apiReady = $admin.loaded && $auth.loaded
|
||||||
|
// if tenant is not set go to it
|
||||||
if (loaded && apiReady && multiTenancyEnabled && !tenantSet) {
|
if (loaded && apiReady && multiTenancyEnabled && !tenantSet) {
|
||||||
$redirect("./auth/org")
|
$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")
|
$redirect("./admin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,6 @@
|
||||||
notifications.error(`Failed to create admin user`)
|
notifications.error(`Failed to create admin user`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeOrg() {
|
|
||||||
auth.setOrg(null)
|
|
||||||
$goto("../auth")
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
@ -62,7 +57,10 @@
|
||||||
Create super admin user
|
Create super admin user
|
||||||
</Button>
|
</Button>
|
||||||
{#if multiTenancyEnabled}
|
{#if multiTenancyEnabled}
|
||||||
<ActionButton quiet on:click={changeOrg}>
|
<ActionButton quiet on:click={() => {
|
||||||
|
admin.unload()
|
||||||
|
$goto("../auth/org")
|
||||||
|
}}>
|
||||||
Change organisation
|
Change organisation
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await admin.init()
|
await admin.init()
|
||||||
auth.checkQueryString()
|
await auth.checkQueryString()
|
||||||
loaded = true
|
loaded = true
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -84,7 +84,10 @@
|
||||||
Forgot password?
|
Forgot password?
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
{#if multiTenancyEnabled}
|
{#if multiTenancyEnabled}
|
||||||
<ActionButton quiet on:click={() => $goto("./org")}>
|
<ActionButton quiet on:click={() => {
|
||||||
|
admin.unload()
|
||||||
|
$goto("./org")
|
||||||
|
}}>
|
||||||
Change organisation
|
Change organisation
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
if (tenantId == null || tenantId === "") {
|
if (tenantId == null || tenantId === "") {
|
||||||
tenantId = "default"
|
tenantId = "default"
|
||||||
}
|
}
|
||||||
auth.setOrg(tenantId)
|
await auth.setOrg(tenantId)
|
||||||
// re-init now org selected
|
// re-init now org selected
|
||||||
await admin.init()
|
await admin.init()
|
||||||
$goto("../")
|
$goto("../")
|
||||||
|
@ -23,8 +23,8 @@
|
||||||
if (evt.key === "Enter") setOrg()
|
if (evt.key === "Enter") setOrg()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(async () => {
|
||||||
auth.checkQueryString()
|
await auth.checkQueryString()
|
||||||
if (!multiTenancyEnabled) {
|
if (!multiTenancyEnabled) {
|
||||||
$goto("../")
|
$goto("../")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
import { redirect } from "@roxi/routify"
|
import { redirect } from "@roxi/routify"
|
||||||
import { auth } from "../stores/portal"
|
import { auth } from "../stores/portal"
|
||||||
|
import { onMount } from "svelte"
|
||||||
|
|
||||||
auth.checkQueryString()
|
auth.checkQueryString()
|
||||||
|
|
||||||
$redirect(`./builder`)
|
onMount(() => {
|
||||||
|
$redirect(`./builder`)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { derived, writable, get } from "svelte/store"
|
import { derived, writable, get } from "svelte/store"
|
||||||
import api from "../../builderStore/api"
|
import api from "../../builderStore/api"
|
||||||
|
import { admin } from "stores/portal"
|
||||||
|
|
||||||
export function createAuthStore() {
|
export function createAuthStore() {
|
||||||
const auth = writable({
|
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 => {
|
auth.update(store => {
|
||||||
store.tenantId = tenantId
|
store.tenantId = tenantId
|
||||||
store.tenantSet = !!tenantId
|
store.tenantSet = !!tenantId
|
||||||
return store
|
return store
|
||||||
})
|
})
|
||||||
|
if (prevId !== tenantId) {
|
||||||
|
// re-init admin after setting org
|
||||||
|
await admin.init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe: store.subscribe,
|
subscribe: store.subscribe,
|
||||||
checkQueryString: () => {
|
checkQueryString: async () => {
|
||||||
const urlParams = new URLSearchParams(window.location.search)
|
const urlParams = new URLSearchParams(window.location.search)
|
||||||
if (urlParams.has("tenantId")) {
|
if (urlParams.has("tenantId")) {
|
||||||
const tenantId = urlParams.get("tenantId")
|
const tenantId = urlParams.get("tenantId")
|
||||||
setOrganisation(tenantId)
|
await setOrganisation(tenantId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setOrg: tenantId => {
|
setOrg: async tenantId => {
|
||||||
setOrganisation(tenantId)
|
await setOrganisation(tenantId)
|
||||||
},
|
},
|
||||||
checkAuth: async () => {
|
checkAuth: async () => {
|
||||||
const response = await api.get("/api/global/users/self")
|
const response = await api.get("/api/global/users/self")
|
||||||
|
|
Loading…
Reference in New Issue