|
|
@ -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") |
|
|
|