Skip to content

Commit

Permalink
chore: support multitenancy domain (#1979)
Browse files Browse the repository at this point in the history
Co-authored-by: Gitanjli Chopra <[email protected]>
  • Loading branch information
gitanjli525 and Gitanjli Chopra authored Jan 3, 2025
1 parent 225af47 commit 93f318c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/entryPoints/AuthModule/AuthUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let redirectToLogin = () => {
open LogicUtils

let authId = getSessionData(~key="auth_id")
let domain = getSessionData(~key="domain")
let domain = getSessionData(~key="domain") // todo: setting domain in session storage shall be removed later

let urlToRedirect = switch (authId->isNonEmptyString, domain->isNonEmptyString) {
| (true, true) => `/login?auth_id=${authId}&domain=${domain}`
Expand Down
2 changes: 1 addition & 1 deletion src/entryPoints/AuthModule/TwoFaAuth/TwoFaAuth.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let make = (~setAuthStatus, ~authType, ~setAuthType) => {
~entityName=USERS,
~userType=#CONNECT_ACCOUNT,
~methodType=Post,
~queryParamerters=Some(`auth_id=${authId}&domain=${domain}`),
~queryParamerters=Some(`auth_id=${authId}&domain=${domain}`), // todo: domain shall be removed from query params later
)
let res = await updateDetails(url, body, Post)
let valuesDict = res->getDictFromJsonObject
Expand Down
6 changes: 3 additions & 3 deletions src/entryPoints/HyperSwitchEntry.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ module HyperSwitchEntryComponent = {
let fetchConfig = async () => {
try {
open LogicUtils
let domain = HyperSwitchEntryUtils.getSessionData(~key="domain", ~defaultValue="default")
let apiURL = `${GlobalVars.getHostUrlWithBasePath}/config/feature?domain=${domain}`
let domain = HyperSwitchEntryUtils.getSessionData(~key="domain", ~defaultValue="")
let apiURL = `${GlobalVars.getHostUrlWithBasePath}/config/feature?domain=${domain}` // todo: domain shall be removed from query params later
let res = await fetchDetails(apiURL)
let featureFlags = res->FeatureFlagUtils.featureFlagType
setFeatureFlag(_ => featureFlags)
Expand Down Expand Up @@ -111,7 +111,7 @@ module HyperSwitchEntryComponent = {

React.useEffect(() => {
let _ = HyperSwitchEntryUtils.setSessionData(~key="auth_id", ~searchParams=url.search)
let _ = HyperSwitchEntryUtils.setSessionData(~key="domain", ~searchParams=url.search)
let _ = HyperSwitchEntryUtils.setSessionData(~key="domain", ~searchParams=url.search) // todo: setting domain in session storage shall be removed later

let _ = fetchConfig()->ignore
None
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Hooks/MerchantSpecificConfigHook.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ let useMerchantSpecificConfig = () => {
HyperswitchAtom.merchantSpecificConfigAtom->Recoil.useRecoilValueFromAtom
let fetchMerchantSpecificConfig = async () => {
try {
let domain = HyperSwitchEntryUtils.getSessionData(~key="domain", ~defaultValue="default")
let merchantConfigURL = ` ${GlobalVars.getHostUrlWithBasePath}/config/merchant?domain=${domain}`
let domain = HyperSwitchEntryUtils.getSessionData(~key="domain", ~defaultValue="")
let merchantConfigURL = ` ${GlobalVars.getHostUrlWithBasePath}/config/merchant?domain=${domain}` // todo: domain shall be removed from query params later
let body =
[
("org_id", orgId->JSON.Encode.string),
Expand Down
7 changes: 5 additions & 2 deletions src/screens/OMPSwitch/OrgSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ module SwitchOrg = {
let _ = await orgSwitch(~expectedOrgId=value, ~currentOrgId=orgId)
setShowModal(_ => false)
} catch {
| _ => showToast(~message="Failed to switch the org! Try again.", ~toastType=ToastError)
| _ => {
showToast(~message="Failed to switch the org! Try again.", ~toastType=ToastError)
setShowModal(_ => false)
}
}
}

Expand Down Expand Up @@ -311,7 +314,7 @@ let make = () => {
dropdownContainerStyle
shouldDisplaySelectedOnTop=true
/>
<RenderIf condition={tenantUser && isTenantAdmin && orgList->Array.length > 20}>
<RenderIf condition={tenantUser && isTenantAdmin && orgList->Array.length >= 20}>
<SwitchOrg setShowModal={setShowSwitchingOrg} />
</RenderIf>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let roleScope = userRole => {
~options=roleScopeArray,
~buttonText="Select Option",
~deselectDisable=true,
~disableSelect=userRole === "org_admin" ? false : true,
~disableSelect=userRole === "org_admin" || userRole === "tenant_admin" ? false : true,
),
~isRequired=true,
)
Expand Down
15 changes: 12 additions & 3 deletions src/server/Server.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,22 @@ let currentCommitHash = nullableGitCommitStr->Option.getOr("no-commit-hash")

let serverHandler: Http.serverHandler = (request, response) => {
let arr = request.url.toString()->String.split("?")
let domain =

let domainFromQueryParam =
arr
->Array.get(1)
->Option.getOr("domain=default")
->Option.getOr("domain=")
->Js.String2.split("=")
->Array.get(1)
->Option.getOr("default")
->Option.getOr("")

let xTenantId = request.headers->Dict.get("x-tenant-id")
let domainFromXTenantId = switch xTenantId->Option.getOr("public") {
| "public" => "default"
| value => value
}

let domain = domainFromQueryParam == "" ? domainFromXTenantId : domainFromQueryParam

let path =
arr
Expand Down

0 comments on commit 93f318c

Please sign in to comment.