Skip to content

Commit

Permalink
Load server info before rendering rest of application (keycloak#27783)
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Koops <jonkoops@gmail.com>
  • Loading branch information
jonkoops committed Mar 13, 2024
1 parent f168b8c commit 7b755e0
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -3,6 +3,7 @@ import { PropsWithChildren, useState } from "react";
import { createNamedContext, useRequiredContext } from "ui-shared";

import { adminClient } from "../../admin-client";
import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner";
import { sortProviders } from "../../util";
import { useFetch } from "../../utils/useFetch";

Expand All @@ -16,10 +17,14 @@ export const useLoginProviders = () =>
sortProviders(useServerInfo().providers!["login-protocol"].providers);

export const ServerInfoProvider = ({ children }: PropsWithChildren) => {
const [serverInfo, setServerInfo] = useState<ServerInfoRepresentation>({});
const [serverInfo, setServerInfo] = useState<ServerInfoRepresentation>();

useFetch(adminClient.serverInfo.find, setServerInfo, []);

if (!serverInfo) {
return <KeycloakSpinner />;
}

return (
<ServerInfoContext.Provider value={serverInfo}>
{children}
Expand Down

0 comments on commit 7b755e0

Please sign in to comment.