Skip to content

Commit f3b7d1d

Browse files
taymoor89ArtieReus
andcommitted
chore(greenhouse): add org to subdomain in non-dev environments
Co-authored-by: Arturo <a.reuschenbach.puncernau@sap.com>
1 parent 42ad17d commit f3b7d1d

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

.changeset/ready-trees-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudoperators/juno-app-greenhouse": patch
3+
---
4+
5+
For non-development environment always put organization name as subdomain.

apps/greenhouse/src/components/AuthProvider.tsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@ import React, { createContext, useContext, useState, useMemo, useRef, useEffect
77
import { oidcSession, mockedSession, tokenSession } from "@cloudoperators/juno-oauth"
88

99
const 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

3240
function resolveMockAuth(value: any) {

0 commit comments

Comments
 (0)