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..6c3609f9d5 --- /dev/null +++ b/packages/builder/src/stores/portal/oidc.ts @@ -0,0 +1,21 @@ +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 configs = await API.getOIDCConfigs(tenantId) + // Just use the first config for now. + // We will be support multiple logins buttons later on. + this.set(configs[0] || {}) + } +} + +export const oidc = new OIDCStore() diff --git a/packages/frontend-core/src/api/configs.ts b/packages/frontend-core/src/api/configs.ts index 82f08e58a7..408180a859 100644 --- a/packages/frontend-core/src/api/configs.ts +++ b/packages/frontend-core/src/api/configs.ts @@ -16,7 +16,7 @@ import { BaseAPIClient } from "./types" export interface ConfigEndpoints { getConfig: (type: ConfigType) => Promise getTenantConfig: (tentantId: string) => Promise - getOIDCConfig: (tenantId: string) => Promise + getOIDCConfigs: (tenantId: string) => Promise getOIDCLogos: () => Promise> saveConfig: (config: SaveConfigRequest) => Promise deleteConfig: (id: string, rev: string) => Promise @@ -73,7 +73,7 @@ export const buildConfigEndpoints = (API: BaseAPIClient): ConfigEndpoints => ({ * Gets the OIDC config for a certain tenant. * @param tenantId the tenant ID to get the config for */ - getOIDCConfig: async tenantId => { + getOIDCConfigs: async tenantId => { return await API.get({ url: `/api/global/configs/public/oidc?tenantId=${tenantId}`, })