Skip to content

introduced AdminClientProvider to make it easier to use#48627

Open
edewit wants to merge 2 commits intokeycloak:mainfrom
edewit:admin-client-provider
Open

introduced AdminClientProvider to make it easier to use#48627
edewit wants to merge 2 commits intokeycloak:mainfrom
edewit:admin-client-provider

Conversation

@edewit
Copy link
Copy Markdown
Contributor

@edewit edewit commented Apr 30, 2026

fixes: #48623
Signed-off-by: Erik Jan de Wit erikjan.dewit@gmail.com

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces an AdminClientProvider to centralize initialization of the Keycloak Admin Client and make consuming the admin-ui package easier for downstream apps/components (per #48623).

Changes:

  • Add AdminClientProvider that initializes and provides adminClient via AdminClientContext.
  • Refactor App to use AdminClientProvider instead of initializing the admin client directly.
  • Update public exports and README usage guidance to include the provider.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
js/apps/admin-ui/src/index.ts Exposes AdminClientProvider via the package entrypoint exports.
js/apps/admin-ui/src/admin-client.tsx Adds AdminClientProvider built on useEnvironment() + AdminClientContext.
js/apps/admin-ui/src/App.tsx Switches app composition to wrap content with AdminClientProvider.
js/apps/admin-ui/README.md Updates consumer-facing setup instructions to use AdminClientProvider.
Comments suppressed due to low confidence (1)

js/apps/admin-ui/src/admin-client.tsx:57

  • AdminClientProvider kicks off an async init and calls setAdminClient when it resolves, but there is no cleanup/guard for unmounts. If the provider unmounts before the promise resolves, React can warn about setting state on an unmounted component. Consider adding an isMounted/aborted flag in the effect cleanup (or an AbortController-style pattern) and only calling setAdminClient when still mounted.

export {
AdminClientContext,
AdminClientProvider,
initAdminClient,
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package README references useAdminClient(), but useAdminClient is not re-exported from the package entrypoint (src/index.ts). Consumers importing from @keycloak/keycloak-admin-ui won’t be able to access it as documented. Either re-export useAdminClient here, or update the README to use only the public exports.

Suggested change
initAdminClient,
initAdminClient,
useAdminClient,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, seems relevant.

Comment on lines +17 to +28
Wrap your app with `KeycloakProvider` from `@keycloak/keycloak-ui-shared` so the realm, client, and server URLs are available. Any subtree that calls `useAdminClient()` (or otherwise needs the Keycloak Admin Client) must also be wrapped with `AdminClientProvider` from this package, **inside** `KeycloakProvider`. `AdminClientProvider` initializes the admin client from the authenticated Keycloak instance and exposes it through `AdminClientContext`.

```jsx
import { KeycloakProvider } from "@keycloak/keycloak-ui-shared";
import { AdminClientProvider } from "@keycloak/keycloak-admin-ui";

//...

<KeycloakProvider environment={{
authServerUrl: "http://localhost:8080",
realm: "master",
clientId: "security-admin-console"
}}>
{/* rest of you application */}
<KeycloakProvider environment={environment}>
<AdminClientProvider>
{/* components that use useAdminClient() */}
</AdminClientProvider>
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section instructs users to call useAdminClient(), but that hook isn’t currently part of the package’s public exports from @keycloak/keycloak-admin-ui (it’s not re-exported from src/index.ts). Please either adjust the docs to match the actual public API, or re-export the hook so the documented import path works.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, seems relevant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is.... fixed it

fixes: keycloak#48623
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +17 to +21
Wrap your app with `KeycloakProvider` from `@keycloak/keycloak-ui-shared` so the realm, client, and server URLs are available. Any subtree that calls `useAdminClient()` (or otherwise needs the Keycloak Admin Client) must also be wrapped with `AdminClientProvider` from this package, **inside** `KeycloakProvider`. `AdminClientProvider` initializes the admin client from the authenticated Keycloak instance and exposes it through `AdminClientContext`.

```jsx
import { KeycloakProvider } from "@keycloak/keycloak-ui-shared";
import { AdminClientProvider } from "@keycloak/keycloak-admin-ui";
Comment thread js/apps/admin-ui/README.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the admin client, from the admin-ui more easy to use

3 participants