File tree Expand file tree Collapse file tree 5 files changed +44
-28
lines changed Expand file tree Collapse file tree 5 files changed +44
-28
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ export type KcContextExtension = {
77 properties : Record < KcEnvName , string > & { } ;
88 // NOTE: Here you can declare more properties to extend the KcContext
99 // See: https://docs.keycloakify.dev/faq-and-help/some-values-you-need-are-missing-from-in-kccontext
10+ client : {
11+ baseUrl ?: string ;
12+ } ;
1013} ;
1114
1215export type KcContextExtensionPerPage = { } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ const kcContextExtension: KcContextExtension = {
99 themeName : themeNames [ 0 ] ,
1010 properties : {
1111 ...kcEnvDefaults
12+ } ,
13+ client : {
14+ baseUrl : "https://my-theme.keycloakify.dev"
1215 }
1316} ;
1417const kcContextExtensionPerPage : KcContextExtensionPerPage = { } ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { useInitialize } from "keycloakify/login/Template.useInitialize";
88import type { I18n } from "./i18n" ;
99import type { KcContext } from "./KcContext" ;
1010import { Header as DsfrHeader } from "@codegouvfr/react-dsfr/Header" ;
11- import { getReferrerUrl } from "./shared/getReferrerUrl " ;
11+ import { redirectUrlOrigin } from "./shared/redirectUriOrigin " ;
1212import { headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display" ;
1313import { Footer as DSFRFooter } from "@codegouvfr/react-dsfr/Footer" ;
1414import { Alert } from "@codegouvfr/react-dsfr/Alert" ;
@@ -77,7 +77,7 @@ export default function Template(props: Props) {
7777 />
7878 }
7979 homeLinkProps = { {
80- href : getReferrerUrl ( ) ,
80+ href : kcContext . client . baseUrl ?? redirectUrlOrigin ,
8181 title : kcContext . realm . displayName
8282 } }
8383 serviceTitle = {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+
2+
3+ const SESSION_STORAGE_KEY = "keycloak-theme-dsfr:redirectUriOrigin" ;
4+
5+ export const redirectUrlOrigin = ( ( ) : string => {
6+ from_url: {
7+ const url = new URL ( window . location . href ) ;
8+
9+ const value = url . searchParams . get ( "redirect_url" ) ;
10+
11+ if ( value === null ) {
12+ // There was no &dark= query param in the URL,
13+ // so we check session storage next.
14+ break from_url;
15+ }
16+
17+
18+ const redirectUriOrigin = new URL ( value ) . origin ;
19+
20+ sessionStorage . setItem ( SESSION_STORAGE_KEY , redirectUriOrigin ) ;
21+
22+ return redirectUriOrigin ;
23+ }
24+
25+ from_session_storage: {
26+ const redirectUriOrigin = sessionStorage . getItem ( SESSION_STORAGE_KEY ) ;
27+
28+ if ( redirectUriOrigin === null ) {
29+ break from_session_storage;
30+ }
31+
32+ return redirectUriOrigin ;
33+ }
34+
35+ return "#" ;
36+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments