@@ -7,26 +7,34 @@ 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+ const isNonDevEnv = url . host . includes ( "dashboard." )
16+
17+ // In non-dev environments, set the organization as subdomain
18+ if ( isNonDevEnv ) {
19+ url . hostname = `${ orgName } .dashboard.${ url . hostname . replace ( / ^ [ ^ . ] + \. / , "" ) } `
20+ window . location . href = url . href
21+ return
22+ }
23+
24+ // Check if the organization name is already in the URL path or hash then don't change it
25+ const currentPath = enableHashedRouting ? url . hash . replace ( "#/" , "" ) : url . pathname
26+ const currentFirstSegment = currentPath . split ( "/" ) . filter ( Boolean ) [ 0 ]
27+ if ( orgName === currentFirstSegment ) return
28+
29+ // if enableHashedRouting is true, set the hash, otherwise set the pathname
30+ const pathWithOrg = `/${ orgName } `
31+ if ( enableHashedRouting ) {
32+ url . hash = pathWithOrg
33+ } else {
34+ url . pathname = pathWithOrg
2935 }
36+ // @ts -expect-error TS(2345): Argument of type 'null' is not assignable to param... Remove this comment to see the full error message
37+ window . history . replaceState ( null , null , url . href )
3038}
3139
3240function resolveMockAuth ( value : any ) {
0 commit comments