From e08e1a7b0dcc7c201f2780da0be217d7dc35afd9 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 6 Jan 2025 11:10:06 +0000 Subject: [PATCH] Convert portal OIDC store to TS --- packages/builder/src/stores/portal/oidc.js | 31 ---------------------- packages/builder/src/stores/portal/oidc.ts | 25 +++++++++++++++++ 2 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 packages/builder/src/stores/portal/oidc.js create mode 100644 packages/builder/src/stores/portal/oidc.ts diff --git a/packages/builder/src/stores/portal/oidc.js b/packages/builder/src/stores/portal/oidc.js deleted file mode 100644 index 65d8eac04c..0000000000 --- a/packages/builder/src/stores/portal/oidc.js +++ /dev/null @@ -1,31 +0,0 @@ -import { writable, get } from "svelte/store" -import { API } from "@/api" -import { auth } from "@/stores/portal" - -const OIDC_CONFIG = { - logo: undefined, - name: undefined, - uuid: undefined, -} - -export function createOidcStore() { - const store = writable(OIDC_CONFIG) - const { set, subscribe } = store - return { - subscribe, - set, - init: async () => { - const tenantId = get(auth).tenantId - 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) - } - }, - } -} - -export const oidc = createOidcStore() diff --git a/packages/builder/src/stores/portal/oidc.ts b/packages/builder/src/stores/portal/oidc.ts new file mode 100644 index 0000000000..a914645135 --- /dev/null +++ b/packages/builder/src/stores/portal/oidc.ts @@ -0,0 +1,25 @@ +import { get } from "svelte/store" +import { API } from "@/api" +import { auth } from "@/stores/portal" +import { BudiStore } from "../BudiStore" +import { PublicOIDCConfig } from "@budibase/types" + +class OIDCStore extends BudiStore { + constructor() { + super({}) + } + + async init() { + const tenantId = get(auth).tenantId + 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. + this.set(config[0]) + } else { + this.set({}) + } + } +} + +export const oidc = new OIDCStore()