Use correct path to account console

Fixes: #27709

Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
Hynek Mlnarik 2024-03-08 12:11:31 +01:00 committed by Hynek Mlnařík
parent 4091baf4c2
commit 26468e11f2
5 changed files with 9 additions and 8 deletions

View file

@ -150,6 +150,7 @@
<script id="environment" type="application/json"> <script id="environment" type="application/json">
{ {
"authUrl": "${authUrl}", "authUrl": "${authUrl}",
"baseUrl": "${baseUrl}",
"realm": "${realm.name}", "realm": "${realm.name}",
"clientId": "${clientId}", "clientId": "${clientId}",
"resourceUrl": "${resourceUrl}", "resourceUrl": "${resourceUrl}",

View file

@ -18,6 +18,8 @@ export type Feature = {
export type Environment = { export type Environment = {
/** The URL to the root of the auth server. */ /** The URL to the root of the auth server. */
authUrl: string; authUrl: string;
/** The URL to the root of the account console. */
baseUrl: string;
/** The realm used to authenticate the user to the Account Console. */ /** The realm used to authenticate the user to the Account Console. */
realm: string; realm: string;
/** The identifier of the client used to authenticate the user to the Account Console. */ /** The identifier of the client used to authenticate the user to the Account Console. */
@ -39,6 +41,7 @@ const match = matchPath(ROOT_PATH, location.pathname);
const defaultEnvironment: Environment = { const defaultEnvironment: Environment = {
authUrl: "http://localhost:8180", authUrl: "http://localhost:8180",
baseUrl: `http://localhost:8180/realms/${match?.params.realm ?? DEFAULT_REALM}/account`,
realm: match?.params.realm ?? DEFAULT_REALM, realm: match?.params.realm ?? DEFAULT_REALM,
clientId: "security-admin-console-v2", clientId: "security-admin-console-v2",
resourceUrl: "http://localhost:8080", resourceUrl: "http://localhost:8080",

View file

@ -20,14 +20,12 @@ import {
useHref, useHref,
useLinkClickHandler, useLinkClickHandler,
useLocation, useLocation,
useParams,
} from "react-router-dom"; } from "react-router-dom";
import fetchContentJson from "../content/fetchContent"; import fetchContentJson from "../content/fetchContent";
import type { Feature } from "../environment"; import { environment, type Feature } from "../environment";
import { TFuncKey } from "../i18n"; import { TFuncKey } from "../i18n";
import { usePromise } from "../utils/usePromise"; import { usePromise } from "../utils/usePromise";
import { useEnvironment } from "./KeycloakContext"; import { useEnvironment } from "./KeycloakContext";
import { getRootPath } from "../utils/getRootPath";
type RootMenuItem = { type RootMenuItem = {
label: TFuncKey; label: TFuncKey;
@ -134,9 +132,7 @@ export const NavLink = ({
isActive, isActive,
children, children,
}: PropsWithChildren<NavLinkProps>) => { }: PropsWithChildren<NavLinkProps>) => {
const { realm } = useParams(); const menuItemPath = `${new URL(environment.baseUrl).pathname}${to}`;
const menuItemPath = `${getRootPath(realm)}/${to}`;
const href = useHref(menuItemPath); const href = useHref(menuItemPath);
const handleClick = useLinkClickHandler(menuItemPath); const handleClick = useLinkClickHandler(menuItemPath);

View file

@ -3,6 +3,7 @@ import type { IndexRouteObject, RouteObject } from "react-router-dom";
import { ErrorPage } from "./root/ErrorPage"; import { ErrorPage } from "./root/ErrorPage";
import { Root } from "./root/Root"; import { Root } from "./root/Root";
import { environment } from "./environment";
const DeviceActivity = lazy(() => import("./account-security/DeviceActivity")); const DeviceActivity = lazy(() => import("./account-security/DeviceActivity"));
const LinkedAccounts = lazy(() => import("./account-security/LinkedAccounts")); const LinkedAccounts = lazy(() => import("./account-security/LinkedAccounts"));
@ -58,7 +59,7 @@ export const PersonalInfoRoute: IndexRouteObject = {
}; };
export const RootRoute: RouteObject = { export const RootRoute: RouteObject = {
path: "/realms/:realm/account", path: new URL(environment.baseUrl).pathname,
element: <Root />, element: <Root />,
errorElement: <ErrorPage />, errorElement: <ErrorPage />,
children: [ children: [

View file

@ -103,7 +103,7 @@ public class AccountConsole implements AccountResourceProvider {
URI adminBaseUri = session.getContext().getUri(UrlType.ADMIN).getBaseUri(); URI adminBaseUri = session.getContext().getUri(UrlType.ADMIN).getBaseUri();
URI authUrl = uriInfo.getBaseUri(); URI authUrl = uriInfo.getBaseUri();
map.put("authUrl", authUrl.getPath().endsWith("/") ? authUrl : authUrl + "/"); map.put("authUrl", authUrl.getPath().endsWith("/") ? authUrl : authUrl + "/");
map.put("baseUrl", accountBaseUrl); map.put("baseUrl", accountBaseUrl.getPath().endsWith("/") ? accountBaseUrl : accountBaseUrl + "/");
map.put("realm", realm); map.put("realm", realm);
map.put("clientId", Constants.ACCOUNT_CONSOLE_CLIENT_ID); map.put("clientId", Constants.ACCOUNT_CONSOLE_CLIENT_ID);
map.put("resourceUrl", Urls.themeRoot(authUrl).getPath() + "/" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "/" + theme.getName()); map.put("resourceUrl", Urls.themeRoot(authUrl).getPath() + "/" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "/" + theme.getName());