Convert portal OIDC store to TS
This commit is contained in:
parent
d9fa8de5ae
commit
e08e1a7b0d
|
@ -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()
|
|
@ -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<PublicOIDCConfig> {
|
||||
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()
|
Loading…
Reference in New Issue