@@ -7,26 +7,33 @@ import React, { createContext, useContext, useState, useMemo, useRef, useEffect
77import { oidcSession , mockedSession , tokenSession } from "@cloudoperators/juno-oauth"
88
99const setOrganizationToUrl = ( groups : any , enableHashedRouting : boolean ) => {
10- const orgString = groups ?. find ( ( g : any ) => g . indexOf ( "organization:" ) === 0 )
11- if ( orgString ) {
12- const name = orgString . split ( ":" ) [ 1 ]
13- let url = new URL ( window . location . href )
14-
15- // Check if the organization name is already in the URL path or hash then don't change it
16- const currentPath = enableHashedRouting ? url . hash . replace ( "#/" , "" ) : url . pathname
17- const currentFirstSegment = currentPath . split ( "/" ) . filter ( Boolean ) [ 0 ]
18- if ( name === currentFirstSegment ) return
19-
20- // if enableHashedRouting is true, set the hash, otherwise set the pathname
21- const pathWithOrg = `/${ name } `
22- if ( enableHashedRouting ) {
23- url . hash = pathWithOrg
24- } else {
25- url . pathname = pathWithOrg
26- }
27- // @ts -expect-error TS(2345): Argument of type 'null' is not assignable to param... Remove this comment to see the full error message
28- window . history . replaceState ( null , null , url . href )
10+ const orgName = groups ?. find ( ( g : any ) => g . startsWith ( "organization:" ) ) ?. split ( ":" ) [ 1 ]
11+
12+ if ( ! orgName ) return
13+
14+ let url = new URL ( window . location . href )
15+
16+ // In non-dev environments, set the organization as subdomain
17+ if ( ! import . meta. env . DEV ) {
18+ url . hostname = `${ orgName } .${ url . hostname } `
19+ window . location . href = url . href
20+ return
21+ }
22+
23+ // Check if the organization name is already in the URL path or hash then don't change it
24+ const currentPath = enableHashedRouting ? url . hash . replace ( "#/" , "" ) : url . pathname
25+ const currentFirstSegment = currentPath . split ( "/" ) . filter ( Boolean ) [ 0 ]
26+ if ( orgName === currentFirstSegment ) return
27+
28+ // if enableHashedRouting is true, set the hash, otherwise set the pathname
29+ const pathWithOrg = `/${ orgName } `
30+ if ( enableHashedRouting ) {
31+ url . hash = pathWithOrg
32+ } else {
33+ url . pathname = pathWithOrg
2934 }
35+ // @ts -expect-error TS(2345): Argument of type 'null' is not assignable to param... Remove this comment to see the full error message
36+ window . history . replaceState ( null , null , url . href )
3037}
3138
3239function resolveMockAuth ( value : any ) {
0 commit comments