SurfSense/surfsense_web/components/providers/runtime-config.tsx
DESKTOP-RTLN3BA\$punk 8df8565e0a feat: enhance document import functionality and runtime configuration
- Added support for watching local folders in the EmbeddedImportMenu, including a new FolderSync icon.
- Introduced onFolderWatched callback to handle folder watch success.
- Updated runtime configuration hooks to allow optional access outside the RuntimeConfigProvider.
- Improved error handling in ZeroProvider for unauthorized access scenarios.
- Refactored base API service to manage desktop authentication more effectively.
2026-07-06 21:31:35 -07:00

53 lines
1.4 KiB
TypeScript

"use client";
import { createContext, useContext } from "react";
export type AuthType = "LOCAL" | "GOOGLE" | string;
export type DeploymentMode = "self-hosted" | "cloud" | string;
export interface RuntimeConfigValue {
authType: AuthType;
etlService: string;
deploymentMode: DeploymentMode;
}
const RuntimeConfigContext = createContext<RuntimeConfigValue | null>(null);
export function RuntimeConfigProvider({
value,
children,
}: {
value: RuntimeConfigValue;
children: React.ReactNode;
}) {
return <RuntimeConfigContext.Provider value={value}>{children}</RuntimeConfigContext.Provider>;
}
export function useRuntimeConfig() {
const context = useContext(RuntimeConfigContext);
if (!context) {
throw new Error("useRuntimeConfig must be used within RuntimeConfigProvider");
}
return context;
}
/** For components that may render outside RuntimeConfigProvider (e.g. anonymous /free pages). */
export function useOptionalRuntimeConfig(): RuntimeConfigValue | null {
return useContext(RuntimeConfigContext);
}
export function useIsLocalAuth() {
return useRuntimeConfig().authType === "LOCAL";
}
export function useIsGoogleAuth() {
return useRuntimeConfig().authType === "GOOGLE";
}
export function useIsSelfHosted() {
return useRuntimeConfig().deploymentMode === "self-hosted";
}
export function useIsCloud() {
return useRuntimeConfig().deploymentMode === "cloud";
}