// config.ts — reads OIDC configuration injected by the Go server into
// window.__LETHE_CONFIG__ (IF1). The injected JSON uses snake_case field names
// (Go struct json tags); this module converts to camelCase for ergonomic use
// throughout the SPA.
export interface LetheConfig {
issuer: string
clientId: string
}
// Raw shape as injected by the Go server (json tags: issuer, client_id).
interface RawLetheConfig {
issuer: string
client_id: string
}
declare global {
interface Window {
__LETHE_CONFIG__?: RawLetheConfig
}
}
/**
* Read the OIDC configuration from window.__LETHE_CONFIG__.
*
* Throws Error('lethe config missing') if the property is absent — fail-fast
* per GPC6. The caller (auth provider mount) should catch this and render an
* "auth-config missing" error card rather than swallowing the exception.
*/
export function readConfig(): LetheConfig {
const raw = window.__LETHE_CONFIG__
if (raw == null) {
throw new Error('lethe config missing')
}
return {
issuer: raw.issuer,
clientId: raw.client_id,
}
}