fix: update currentOrgDomain to derive root domain from window location

This commit is contained in:
Rotimi Best
2025-07-21 21:33:50 +01:00
parent be0d05abc6
commit 8a6d35b8ed
+23 -9
View File
@@ -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}`
: '';
});