From 8a6d35b8ede600d208f8043cdad1819233a43d76 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Mon, 21 Jul 2025 21:33:50 +0100 Subject: [PATCH] fix: update currentOrgDomain to derive root domain from window location --- apps/dashboard/src/lib/utils/store/org.ts | 32 ++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/dashboard/src/lib/utils/store/org.ts b/apps/dashboard/src/lib/utils/store/org.ts index 093a76de..a4bf8151 100644 --- a/apps/dashboard/src/lib/utils/store/org.ts +++ b/apps/dashboard/src/lib/utils/store/org.ts @@ -1,12 +1,13 @@ -import { browser, dev } from '$app/environment'; -import { env } from '$env/dynamic/public'; -import { ROLE } from '$lib/utils/constants/roles'; -import type { UserLessonDataType } from '$lib/utils/types'; -import { PLAN } from 'shared/src/plans/constants'; -import type { Writable } from 'svelte/store'; -import { derived, writable } from 'svelte/store'; -import { STEPS } from '../constants/quiz'; import type { CurrentOrg, OrgAudience, OrgTeamMember } from '../types/org'; +import { browser, dev } from '$app/environment'; +import { derived, writable } from 'svelte/store'; + +import { PLAN } from 'shared/src/plans/constants'; +import { ROLE } from '$lib/utils/constants/roles'; +import { STEPS } from '../constants/quiz'; +import type { UserLessonDataType } from '$lib/utils/types'; +import type { Writable } from 'svelte/store'; +import { env } from '$env/dynamic/public'; export const defaultCurrentOrgState: CurrentOrg = { id: '', @@ -45,12 +46,25 @@ export const currentOrgPath = derived(currentOrg, ($currentOrg) => export const currentOrgDomain = derived(currentOrg, ($currentOrg) => { const browserOrigin = dev && browser && window.location.origin; + + // Get the root domain from window.location + let rootDomain = ''; + if (browser && typeof window !== 'undefined') { + const host = window.location.hostname; + const parts = host.split('.'); + if (parts.length >= 2) { + rootDomain = parts.slice(-2).join('.'); + } else { + rootDomain = host; + } + } + return browserOrigin ? browserOrigin : $currentOrg.customDomain && $currentOrg.isCustomDomainVerified ? `https://${$currentOrg.customDomain}` : $currentOrg.siteName - ? `https://${$currentOrg.siteName}.classroomio.com` + ? `https://${$currentOrg.siteName}.${rootDomain}` : ''; });