refactor(ui-server-auth,server): use better design of signin page

This commit is contained in:
Neko Ayaka
2026-04-10 16:25:11 +08:00
parent f769580099
commit abc0cb0bc7
15 changed files with 351 additions and 451 deletions
@@ -0,0 +1,41 @@
import { SERVER_URL } from '@proj-airi/stage-ui/libs/server'
export interface ServerAuthBootstrapContext {
apiServerUrl: string
currentUrl: string
oidcCallback?: {
code: string
error: string
errorDescription: string
state: string
}
}
const SCRIPT_ID = 'airi-server-auth-context'
let cachedContext: ServerAuthBootstrapContext | null | undefined
export function getServerAuthBootstrapContext(): ServerAuthBootstrapContext | null {
if (cachedContext !== undefined)
return cachedContext
const element = document.getElementById(SCRIPT_ID)
if (!element) {
cachedContext = null
return cachedContext
}
try {
const parsed = JSON.parse(element.textContent ?? '') as Partial<ServerAuthBootstrapContext>
cachedContext = {
apiServerUrl: parsed.apiServerUrl ?? SERVER_URL,
currentUrl: parsed.currentUrl ?? window.location.href,
oidcCallback: parsed.oidcCallback,
}
return cachedContext
}
catch {
cachedContext = null
return cachedContext
}
}