1
0
Fork 0
mirror of synced 2024-09-21 20:01:32 +12:00
budibase/packages/builder/src/stores/portal/oidc.js

39 lines
805 B
JavaScript
Raw Normal View History

import { writable, get } from "svelte/store"
import { API } from "api"
import { auth } from "stores/portal"
2021-07-14 01:54:20 +12:00
const OIDC_CONFIG = {
logo: undefined,
name: undefined,
uuid: undefined,
2021-07-14 01:54:20 +12:00
}
export function createOidcStore() {
const store = writable(OIDC_CONFIG)
const { set, subscribe } = store
async function init() {
const tenantId = get(auth).tenantId
try {
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)
}
} catch (error) {
2021-07-14 01:54:20 +12:00
set(OIDC_CONFIG)
}
}
return {
subscribe,
set,
init,
}
}
export const oidc = createOidcStore()