fixed ssr

This commit is contained in:
2025-10-16 17:53:09 +02:00
parent 487d7d0cc9
commit 5d964dfd54
4 changed files with 38 additions and 2 deletions

2
.gitignore vendored
View File

@@ -65,4 +65,4 @@ frontend/.next/
frontend/node_modules/ frontend/node_modules/
node_modules/ node_modules/
venv/ venv/
venv_memory_monitor/

View File

View File

@@ -31,6 +31,18 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined)
export function useAuth() { export function useAuth() {
const context = useContext(AuthContext) const context = useContext(AuthContext)
if (context === undefined) { 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") throw new Error("useAuth must be used within an AuthProvider")
} }
return context return context

View File

@@ -87,6 +87,30 @@ const PluginContext = createContext<PluginContextType | undefined>(undefined);
export const usePlugin = () => { export const usePlugin = () => {
const context = useContext(PluginContext); const context = useContext(PluginContext);
if (context === undefined) { 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'); throw new Error('usePlugin must be used within a PluginProvider');
} }
return context; return context;