Enable to redirect back to the application from the account pages

This commit is contained in:
garronej 2023-04-20 13:05:01 +02:00
parent c170345550
commit 34e47cccc1
2 changed files with 10 additions and 2 deletions

View File

@ -26,7 +26,13 @@ export declare namespace KcContext {
resourceUrl: string;
resourcesCommonPath: string;
resourcesPath: string;
/** @deprecated, not present in recent keycloak version apparently, use kcContext.referrer instead */
referrerURI?: string;
// Present only if redirected to account page with ?referrer=xxx&referrer_uri=http...
referrer?: {
url: string; // The url of the App
name: string; // NOTE: Client id
};
getLogoutUrl: () => string;
};
features: {

View File

@ -15,7 +15,7 @@ export default function Account(props: PageProps<Extract<KcContext, { pageId: "a
}
});
const { url, realm, messagesPerField, stateChecker, account } = kcContext;
const { url, realm, messagesPerField, stateChecker, account, referrer } = kcContext;
const { msg } = i18n;
@ -99,7 +99,9 @@ export default function Account(props: PageProps<Extract<KcContext, { pageId: "a
<div className="form-group">
<div id="kc-form-buttons" className="col-md-offset-2 col-md-10 submit">
<div>
{url.referrerURI !== undefined && <a href={url.referrerURI}>{msg("backToApplication")}</a>}
{(referrer !== undefined || url.referrerURI !== undefined) && (
<a href={referrer?.url ?? url.referrerURI}>{msg("backToApplication")}</a>
)}
<button
type="submit"
className={clsx(