fix(frontend): block access until runtime config is loaded
This commit is contained in:
parent
e1bbd94224
commit
1eb3da814d
1 changed files with 13 additions and 2 deletions
|
|
@ -36,7 +36,10 @@ export function ConfigProvider({ children }: { children: ReactNode }) {
|
||||||
const response = await fetch('/api/config');
|
const response = await fetch('/api/config');
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
console.log('[Config] Loaded runtime config:', data);
|
||||||
setConfig(data);
|
setConfig(data);
|
||||||
|
// Also update the global cached config for non-React usage
|
||||||
|
cachedConfig = data;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('[Config] Failed to fetch runtime config, using defaults:', error);
|
console.warn('[Config] Failed to fetch runtime config, using defaults:', error);
|
||||||
|
|
@ -48,6 +51,14 @@ export function ConfigProvider({ children }: { children: ReactNode }) {
|
||||||
fetchConfig();
|
fetchConfig();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen w-screen items-center justify-center bg-background">
|
||||||
|
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfigContext.Provider value={{ config, isLoading }}>
|
<ConfigContext.Provider value={{ config, isLoading }}>
|
||||||
{children}
|
{children}
|
||||||
|
|
@ -70,7 +81,7 @@ let cachedConfig: RuntimeConfig | null = null;
|
||||||
|
|
||||||
export async function getConfig(): Promise<RuntimeConfig> {
|
export async function getConfig(): Promise<RuntimeConfig> {
|
||||||
if (cachedConfig) return cachedConfig;
|
if (cachedConfig) return cachedConfig;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/config');
|
const response = await fetch('/api/config');
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
@ -80,7 +91,7 @@ export async function getConfig(): Promise<RuntimeConfig> {
|
||||||
} catch {
|
} catch {
|
||||||
console.warn('[Config] Failed to fetch config, using defaults');
|
console.warn('[Config] Failed to fetch config, using defaults');
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultConfig;
|
return defaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue