mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-17 23:44:24 +01:00
fixed ssr
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -65,4 +65,4 @@ frontend/.next/
|
|||||||
frontend/node_modules/
|
frontend/node_modules/
|
||||||
node_modules/
|
node_modules/
|
||||||
venv/
|
venv/
|
||||||
|
venv_memory_monitor/
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user