introduced AdminClientProvider to make it easier to use#48627
introduced AdminClientProvider to make it easier to use#48627edewit wants to merge 2 commits intokeycloak:mainfrom
Conversation
There was a problem hiding this comment.
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
AdminClientProviderthat initializes and providesadminClientviaAdminClientContext. - Refactor
Appto useAdminClientProviderinstead 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
AdminClientProviderkicks off an async init and callssetAdminClientwhen 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 anisMounted/abortedflag in the effect cleanup (or an AbortController-style pattern) and only callingsetAdminClientwhen still mounted.
| export { | ||
| AdminClientContext, | ||
| AdminClientProvider, | ||
| initAdminClient, |
There was a problem hiding this comment.
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.
| initAdminClient, | |
| initAdminClient, | |
| useAdminClient, |
| 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> |
There was a problem hiding this comment.
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.
fixes: keycloak#48623 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
50ee3ae to
b318433
Compare
| 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"; |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Erik Jan de Wit <edewit@redhat.com>
fixes: #48623
Signed-off-by: Erik Jan de Wit erikjan.dewit@gmail.com