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 = {
7
7
properties : Record < KcEnvName , string > & { } ;
8
8
// NOTE: Here you can declare more properties to extend the KcContext
9
9
// See: https://docs.keycloakify.dev/faq-and-help/some-values-you-need-are-missing-from-in-kccontext
10
+ client : {
11
+ baseUrl ?: string ;
12
+ } ;
10
13
} ;
11
14
12
15
export type KcContextExtensionPerPage = { } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ const kcContextExtension: KcContextExtension = {
9
9
themeName : themeNames [ 0 ] ,
10
10
properties : {
11
11
...kcEnvDefaults
12
+ } ,
13
+ client : {
14
+ baseUrl : "https://my-theme.keycloakify.dev"
12
15
}
13
16
} ;
14
17
const kcContextExtensionPerPage : KcContextExtensionPerPage = { } ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { useInitialize } from "keycloakify/login/Template.useInitialize";
8
8
import type { I18n } from "./i18n" ;
9
9
import type { KcContext } from "./KcContext" ;
10
10
import { Header as DsfrHeader } from "@codegouvfr/react-dsfr/Header" ;
11
- import { getReferrerUrl } from "./shared/getReferrerUrl " ;
11
+ import { redirectUrlOrigin } from "./shared/redirectUriOrigin " ;
12
12
import { headerFooterDisplayItem } from "@codegouvfr/react-dsfr/Display" ;
13
13
import { Footer as DSFRFooter } from "@codegouvfr/react-dsfr/Footer" ;
14
14
import { Alert } from "@codegouvfr/react-dsfr/Alert" ;
@@ -77,7 +77,7 @@ export default function Template(props: Props) {
77
77
/>
78
78
}
79
79
homeLinkProps = { {
80
- href : getReferrerUrl ( ) ,
80
+ href : kcContext . client . baseUrl ?? redirectUrlOrigin ,
81
81
title : kcContext . realm . displayName
82
82
} }
83
83
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