changed how whoAmI uses the admin client (#216)

this avoids a circle dependency on realm
This commit is contained in:
Erik Jan de Wit 2020-11-12 20:16:41 +01:00 committed by GitHub
parent b06cea6fd9
commit 9eabcdbee4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 20 deletions

View file

@ -6,7 +6,6 @@ import { Header } from "./PageHeader";
import { PageNav } from "./PageNav";
import { Help } from "./components/help-enabler/HelpHeader";
import { WhoAmIContextProvider } from "./context/whoami/WhoAmI";
import { ServerInfoProvider } from "./context/server-info/ServerInfoProvider";
import { AlertProvider } from "./components/alert/Alerts";
@ -16,15 +15,13 @@ import { PageBreadCrumbs } from "./components/bread-crumb/PageBreadCrumbs";
import { ForbiddenSection } from "./ForbiddenSection";
const AppContexts = ({ children }: { children: ReactNode }) => (
<WhoAmIContextProvider>
<AccessContextProvider>
<Help>
<AlertProvider>
<ServerInfoProvider>{children}</ServerInfoProvider>
</AlertProvider>
</Help>
</AccessContextProvider>
</WhoAmIContextProvider>
<AccessContextProvider>
<Help>
<AlertProvider>
<ServerInfoProvider>{children}</ServerInfoProvider>
</AlertProvider>
</Help>
</AccessContextProvider>
);
// If someone tries to go directly to a route they don't

View file

@ -1,8 +1,8 @@
import React from "react";
import React, { useContext } from "react";
import i18n from "../../i18n";
import { DataLoader } from "../../components/data-loader/DataLoader";
import { useAdminClient } from "../auth/AdminClient";
import { AdminClient } from "../auth/AdminClient";
import WhoAmIRepresentation, {
AccessType,
} from "keycloak-admin/lib/defs/whoAmIRepresentation";
@ -53,7 +53,7 @@ export const WhoAmIContext = React.createContext(new WhoAmI());
type WhoAmIProviderProps = { children: React.ReactNode };
export const WhoAmIContextProvider = ({ children }: WhoAmIProviderProps) => {
const adminClient = useAdminClient();
const adminClient = useContext(AdminClient)!;
const whoAmILoader = async () => {
if (adminClient.keycloak === undefined) return undefined;

View file

@ -2,20 +2,23 @@ import React from "react";
import ReactDom from "react-dom";
import i18n from "./i18n";
import { AdminClient } from "./context/auth/AdminClient";
import init from "./context/auth/keycloak";
import { App } from "./App";
import { AdminClient } from "./context/auth/AdminClient";
import { RealmContextProvider } from "./context/realm-context/RealmContext";
import { WhoAmIContextProvider } from "./context/whoami/WhoAmI";
import { App } from "./App";
console.info("supported languages", ...i18n.languages);
init().then((adminClient) => {
ReactDom.render(
<RealmContextProvider>
<AdminClient.Provider value={adminClient}>
<App />
</AdminClient.Provider>
</RealmContextProvider>,
<AdminClient.Provider value={adminClient}>
<WhoAmIContextProvider>
<RealmContextProvider>
<App />
</RealmContextProvider>
</WhoAmIContextProvider>
</AdminClient.Provider>,
document.getElementById("app")
);
});