~bigbes/lethe

ref: a1e67ca703ed1c77d8629f2bdbb57668f85c98c2 lethe/web/src/lib/config.ts -rw-r--r-- 1.1 KiB
a1e67ca7 — Eugene Blikh collector: add Claude Code parser 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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,
  }
}