2021-08-05 20:59:08 +12:00
|
|
|
import { writable, get } from "svelte/store"
|
2022-01-21 22:10:59 +13:00
|
|
|
import { API } from "api"
|
2021-08-05 20:59:08 +12:00
|
|
|
import { auth } from "stores/portal"
|
2021-07-14 01:54:20 +12:00
|
|
|
|
|
|
|
const OIDC_CONFIG = {
|
|
|
|
logo: undefined,
|
|
|
|
name: undefined,
|
2021-07-14 02:52:21 +12:00
|
|
|
uuid: undefined,
|
2021-07-14 01:54:20 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
export function createOidcStore() {
|
|
|
|
const store = writable(OIDC_CONFIG)
|
|
|
|
const { set, subscribe } = store
|
2022-01-25 03:32:27 +13:00
|
|
|
return {
|
|
|
|
subscribe,
|
|
|
|
set,
|
|
|
|
init: async () => {
|
|
|
|
const tenantId = get(auth).tenantId
|
2022-01-21 22:10:59 +13:00
|
|
|
const config = await API.getOIDCConfig(tenantId)
|
|
|
|
if (Object.keys(config || {}).length) {
|
|
|
|
// Just use the first config for now.
|
|
|
|
// We will be support multiple logins buttons later on.
|
|
|
|
set(...config)
|
|
|
|
} else {
|
|
|
|
set(OIDC_CONFIG)
|
|
|
|
}
|
2022-01-25 03:32:27 +13:00
|
|
|
},
|
2021-07-14 01:54:20 +12:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const oidc = createOidcStore()
|