Pass login realm to WhoAmI (#989)

Co-authored-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Jon Koops 2021-08-11 16:38:55 +02:00 committed by GitHub
parent 54dca4df65
commit 71b1c4a444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -20,7 +20,9 @@ describe("Realms test", () => {
after(async () => {
const client = new AdminClient();
await client.deleteRealm(testRealmName);
[testRealmName, "one", "two"].map(
async (realm) => await client.deleteRealm(realm)
);
});
it("should fail creating Master realm", () => {
@ -39,6 +41,25 @@ describe("Realms test", () => {
masthead.checkNotificationMessage("Realm created");
});
it("should create realm from new a realm", () => {
sidebarPage.goToCreateRealm();
createRealmPage.fillRealmName("one").createRealm();
const fetchUrl = "/auth/admin/realms";
cy.intercept(fetchUrl).as("fetch");
masthead.checkNotificationMessage("Realm created");
cy.wait(["@fetch"]);
sidebarPage.goToCreateRealm();
createRealmPage.fillRealmName("two").createRealm();
masthead.checkNotificationMessage("Realm created");
cy.wait(["@fetch"]);
});
it("should change to Test realm", () => {
sidebarPage.getCurrentRealm().should("eq", "Master");

View file

@ -1,6 +1,7 @@
import type WhoAmIRepresentation from "keycloak-admin/lib/defs/whoAmIRepresentation";
import type { AccessType } from "keycloak-admin/lib/defs/whoAmIRepresentation";
import React, { FunctionComponent, useState } from "react";
import environment from "../../environment";
import i18n from "../../i18n";
import useRequiredContext from "../../utils/useRequiredContext";
import { useAdminClient, useFetch } from "../auth/AdminClient";
@ -56,7 +57,7 @@ export const WhoAmIContextProvider: FunctionComponent = ({ children }) => {
const [key, setKey] = useState(0);
useFetch(
() => adminClient.whoAmI.find(),
() => adminClient.whoAmI.find({ realm: environment.loginRealm }),
(me) => {
const whoAmI = new WhoAmI(me);
setWhoAmI(whoAmI);