Merge pull request #15306 from Budibase/type-portal-oidc-store

Convert portal OIDC store to TS
This commit is contained in:
Andrew Kingston 2025-01-09 09:03:59 +00:00 committed by GitHub
commit 7ce57e0684
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 33 deletions

View File

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

View File

@ -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<PublicOIDCConfig> {
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()

View File

@ -16,7 +16,7 @@ import { BaseAPIClient } from "./types"
export interface ConfigEndpoints { export interface ConfigEndpoints {
getConfig: (type: ConfigType) => Promise<FindConfigResponse> getConfig: (type: ConfigType) => Promise<FindConfigResponse>
getTenantConfig: (tentantId: string) => Promise<GetPublicSettingsResponse> getTenantConfig: (tentantId: string) => Promise<GetPublicSettingsResponse>
getOIDCConfig: (tenantId: string) => Promise<GetPublicOIDCConfigResponse> getOIDCConfigs: (tenantId: string) => Promise<GetPublicOIDCConfigResponse>
getOIDCLogos: () => Promise<Config<OIDCLogosConfig>> getOIDCLogos: () => Promise<Config<OIDCLogosConfig>>
saveConfig: (config: SaveConfigRequest) => Promise<SaveConfigResponse> saveConfig: (config: SaveConfigRequest) => Promise<SaveConfigResponse>
deleteConfig: (id: string, rev: string) => Promise<DeleteConfigResponse> deleteConfig: (id: string, rev: string) => Promise<DeleteConfigResponse>
@ -73,7 +73,7 @@ export const buildConfigEndpoints = (API: BaseAPIClient): ConfigEndpoints => ({
* Gets the OIDC config for a certain tenant. * Gets the OIDC config for a certain tenant.
* @param tenantId the tenant ID to get the config for * @param tenantId the tenant ID to get the config for
*/ */
getOIDCConfig: async tenantId => { getOIDCConfigs: async tenantId => {
return await API.get({ return await API.get({
url: `/api/global/configs/public/oidc?tenantId=${tenantId}`, url: `/api/global/configs/public/oidc?tenantId=${tenantId}`,
}) })