mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-17 07:24:34 +01:00
fixed ssr
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -64,5 +64,5 @@ backend/modules/rag/__pycache__/
|
||||
frontend/.next/
|
||||
frontend/node_modules/
|
||||
node_modules/
|
||||
venv/
|
||||
|
||||
venv/
|
||||
venv_memory_monitor/
|
||||
|
||||
@@ -31,6 +31,18 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined)
|
||||
export function useAuth() {
|
||||
const context = useContext(AuthContext)
|
||||
if (context === undefined) {
|
||||
// During SSR/SSG, return default values instead of throwing
|
||||
if (typeof window === "undefined") {
|
||||
return {
|
||||
user: null,
|
||||
isLoading: true,
|
||||
isAuthenticated: false,
|
||||
login: async () => {},
|
||||
logout: () => {},
|
||||
register: async () => {},
|
||||
refreshToken: async () => {},
|
||||
}
|
||||
}
|
||||
throw new Error("useAuth must be used within an AuthProvider")
|
||||
}
|
||||
return context
|
||||
|
||||
@@ -87,6 +87,30 @@ const PluginContext = createContext<PluginContextType | undefined>(undefined);
|
||||
export const usePlugin = () => {
|
||||
const context = useContext(PluginContext);
|
||||
if (context === undefined) {
|
||||
// During SSR/SSG, return default values instead of throwing
|
||||
if (typeof window === "undefined") {
|
||||
return {
|
||||
installedPlugins: [],
|
||||
availablePlugins: [],
|
||||
pluginConfigurations: {},
|
||||
loading: false,
|
||||
error: null,
|
||||
refreshInstalledPlugins: async () => {},
|
||||
searchAvailablePlugins: async () => {},
|
||||
installPlugin: async () => false,
|
||||
uninstallPlugin: async () => false,
|
||||
enablePlugin: async () => false,
|
||||
disablePlugin: async () => false,
|
||||
loadPlugin: async () => false,
|
||||
unloadPlugin: async () => false,
|
||||
getPluginConfiguration: async () => null,
|
||||
savePluginConfiguration: async () => false,
|
||||
getPluginSchema: async () => null,
|
||||
getPluginPages: () => [],
|
||||
isPluginPageAuthorized: () => false,
|
||||
getPluginComponent: () => null,
|
||||
};
|
||||
}
|
||||
throw new Error('usePlugin must be used within a PluginProvider');
|
||||
}
|
||||
return context;
|
||||
|
||||
Reference in New Issue
Block a user