Throw error when server context can't be loaded (#2635)
This commit is contained in:
parent
5685b2a825
commit
2bf30c9203
3 changed files with 18 additions and 29 deletions
26
src/App.tsx
26
src/App.tsx
|
@ -41,9 +41,7 @@ const AppContexts: FunctionComponent<AdminClientProps> = ({
|
||||||
<AccessContextProvider>
|
<AccessContextProvider>
|
||||||
<Help>
|
<Help>
|
||||||
<AlertProvider>
|
<AlertProvider>
|
||||||
<ServerInfoProvider>
|
<SubGroups>{children}</SubGroups>
|
||||||
<SubGroups>{children}</SubGroups>
|
|
||||||
</ServerInfoProvider>
|
|
||||||
</AlertProvider>
|
</AlertProvider>
|
||||||
</Help>
|
</Help>
|
||||||
</AccessContextProvider>
|
</AccessContextProvider>
|
||||||
|
@ -91,16 +89,18 @@ export const App = ({ adminClient }: AdminClientProps) => {
|
||||||
window.location.origin + window.location.pathname)
|
window.location.origin + window.location.pathname)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Switch>
|
<ServerInfoProvider>
|
||||||
{routes.map((route, i) => (
|
<Switch>
|
||||||
<Route
|
{routes.map((route, i) => (
|
||||||
exact={route.matchOptions?.exact ?? true}
|
<Route
|
||||||
key={i}
|
exact={route.matchOptions?.exact ?? true}
|
||||||
path={route.path}
|
key={i}
|
||||||
component={() => <SecuredRoute route={route} />}
|
path={route.path}
|
||||||
/>
|
component={() => <SecuredRoute route={route} />}
|
||||||
))}
|
/>
|
||||||
</Switch>
|
))}
|
||||||
|
</Switch>
|
||||||
|
</ServerInfoProvider>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</Page>
|
</Page>
|
||||||
</AppContexts>
|
</AppContexts>
|
||||||
|
|
|
@ -2,8 +2,8 @@ import React, { createContext, FunctionComponent, useState } from "react";
|
||||||
|
|
||||||
import type { ServerInfoRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/serverInfoRepesentation";
|
import type { ServerInfoRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/serverInfoRepesentation";
|
||||||
import { sortProviders } from "../../util";
|
import { sortProviders } from "../../util";
|
||||||
import useRequiredContext from "../../utils/useRequiredContext";
|
|
||||||
import { useAdminClient, useFetch } from "../auth/AdminClient";
|
import { useAdminClient, useFetch } from "../auth/AdminClient";
|
||||||
|
import useRequiredContext from "../../utils/useRequiredContext";
|
||||||
|
|
||||||
export const ServerInfoContext = createContext<
|
export const ServerInfoContext = createContext<
|
||||||
ServerInfoRepresentation | undefined
|
ServerInfoRepresentation | undefined
|
||||||
|
@ -11,25 +11,14 @@ export const ServerInfoContext = createContext<
|
||||||
|
|
||||||
export const useServerInfo = () => useRequiredContext(ServerInfoContext);
|
export const useServerInfo = () => useRequiredContext(ServerInfoContext);
|
||||||
|
|
||||||
export const useLoginProviders = () => {
|
export const useLoginProviders = () =>
|
||||||
return sortProviders(useServerInfo().providers!["login-protocol"].providers);
|
sortProviders(useServerInfo().providers!["login-protocol"].providers);
|
||||||
};
|
|
||||||
|
|
||||||
export const ServerInfoProvider: FunctionComponent = ({ children }) => {
|
export const ServerInfoProvider: FunctionComponent = ({ children }) => {
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const [serverInfo, setServerInfo] = useState<ServerInfoRepresentation>({});
|
const [serverInfo, setServerInfo] = useState<ServerInfoRepresentation>({});
|
||||||
|
|
||||||
useFetch(
|
useFetch(adminClient.serverInfo.find, setServerInfo, []);
|
||||||
async () => {
|
|
||||||
try {
|
|
||||||
return await adminClient.serverInfo.find();
|
|
||||||
} catch (error) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setServerInfo,
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ServerInfoContext.Provider value={serverInfo}>
|
<ServerInfoContext.Provider value={serverInfo}>
|
||||||
|
|
|
@ -77,7 +77,7 @@ const configuredI18n = i18n
|
||||||
translator: any
|
translator: any
|
||||||
) {
|
) {
|
||||||
const override: string =
|
const override: string =
|
||||||
translator.resourceStore.data[translator.language].overrides[key];
|
translator.resourceStore.data[translator.language].overrides?.[key];
|
||||||
return override || value;
|
return override || value;
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue