Merge branch 'main' of https://github.com/classroomio/classroomio into feat/release-v2

This commit is contained in:
Rotimi Best
2025-11-08 20:22:53 +01:00
9 changed files with 84 additions and 74 deletions
+10 -7
View File
@@ -100,11 +100,9 @@ export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
return response;
}
const answer = !!subdomain;
console.log('subdomain', subdomain);
response.isOrgSite = debugMode || answer;
response.isOrgSite = debugMode || !!subdomain;
response.orgSiteName = debugMode ? _orgSiteName : subdomain;
response.org = (await getCurrentOrg(response.orgSiteName, true)) || null;
@@ -172,11 +170,16 @@ function getBaseMetaTags(url: URL) {
}
function getSubdomain(url: URL) {
const host = url.host.replace('www.', '');
const parts = host?.split('.');
const host = url.hostname.replace('www.', '');
const parts = host.split('.');
const appHost = env.PRIVATE_APP_HOST;
if (host?.endsWith(env.PRIVATE_APP_HOST)) {
return parts?.length >= 3 ? parts[0] : null;
const appHostParts = appHost.split('.');
const isAppHost = parts.slice(-appHostParts.length).join('.') === appHost;
if (isAppHost) {
// Subdomain exists only if extra part(s) before main domain
return parts.length > appHostParts.length ? parts[0] : null;
}
return null;
+32 -35
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { browser } from '$app/environment';
// import { browser } from '$app/environment';
import { page } from '$app/stores';
import debounce from 'lodash/debounce';
@@ -28,11 +28,14 @@
import { globalStore } from '$lib/utils/store/app';
import { currentOrg } from '$lib/utils/store/org';
import { isMobile } from '$lib/utils/store/useMobile';
import { Theme } from 'carbon-components-svelte';
import type { CarbonTheme } from 'carbon-components-svelte/types/Theme/Theme.svelte';
// import { Theme } from 'carbon-components-svelte';
// import type { CarbonTheme } from 'carbon-components-svelte/types/Theme/Theme.svelte';
import merge from 'lodash/merge';
import { onMount } from 'svelte';
import { MetaTags } from 'svelte-meta-tags';
import isPublicRoute from '$lib/utils/functions/routes/isPublicRoute';
import { hasSession } from '$lib/utils/functions/supabase';
import { goto } from '$app/navigation';
import { ModeWatcher } from '@cio/ui/base/dark-mode';
@@ -43,7 +46,7 @@
let supabase = getSupabase();
let path = $derived($page.url?.pathname?.replace('/', ''));
let queryParam = $page.url?.search;
let carbonTheme: CarbonTheme = $derived($globalStore.isDark ? 'g100' : 'white');
// let carbonTheme: CarbonTheme = $derived($globalStore.isDark ? 'g100' : 'white');
function handleResize() {
isMobile.update(() => window.innerWidth <= 760);
@@ -51,33 +54,43 @@
const getProfileDebounced = debounce(getProfile, 1000);
onMount(() => {
function pageSetup() {
console.log(
'Welcome to ClassroomIO, we are grateful you chose us.',
$page.url.host,
`\nIs student domain: ${data.isOrgSite}`
`\nIs student domain: ${data.isOrgSite}`,
data
);
if (browser) {
// Update theme - dark or light mode
// $globalStore.isDark = localStorage.getItem('mode') === 'dark';
// toggleBodyByMode($globalStore.isDark);
// $globalStore.isDark = localStorage.getItem('mode') === 'dark';
// toggleBodyByMode($globalStore.isDark);
if (data.isOrgSite && data.org?.theme) {
setTheme(data.org?.theme);
}
}
setupAnalytics();
handleResize();
// if (!isSupabaseTokenInLocalStorage() && !isPublicRoute($page.url?.pathname)) {
// console.log('No auth token and is not a public route, redirect to login', path);
// return goto('/login?redirect=/' + path);
// }
if (!data.isOrgSite || !data.org) return;
$globalStore.orgSiteName = data.orgSiteName;
$globalStore.isOrgSite = data.isOrgSite;
currentOrg.set(data.org);
// Setup internal analytics
initOrgAnalytics(data.orgSiteName);
setTheme(data.org?.theme);
}
onMount(() => {
pageSetup();
if (!hasSession() && !isPublicRoute($page.url?.pathname)) {
console.log('No auth token and is not a public route, redirect to login', path);
return goto('/login?redirect=/' + path);
}
const { data: authListener } = supabase.auth.onAuthStateChange((event) => {
// Log key events
console.log(`event`, event);
if (path.includes('reset')) {
@@ -85,10 +98,8 @@
return;
}
// Skip Authentication
if (data.skipAuth) return;
// Authentication Steps
if (event === 'SIGNED_IN' || event === 'INITIAL_SESSION') {
getProfileDebounced({
path,
@@ -97,22 +108,8 @@
orgSiteName: data.orgSiteName
});
}
// else if (!['TOKEN_REFRESHED'].includes(event)) {
// console.log('not logged in, go to login');
// return goto('/login');
// }
});
if (data.isOrgSite && data.org && !$currentOrg.siteName) {
$globalStore.orgSiteName = data.orgSiteName;
$globalStore.isOrgSite = data.isOrgSite;
currentOrg.set(data.org);
// Setup internal analytics
initOrgAnalytics(data.orgSiteName);
}
return () => {
console.log('unsubscribed');
authListener.subscription.unsubscribe();
@@ -110,6 +110,14 @@
}
onMount(async () => {
// check if user has session, if not redirect to sign up with redirect back to this page
const {
data: { session }
} = await supabase.auth.getSession();
if (!session) {
return goto(`/login?redirect=${$page.url?.pathname || ''}`);
}
setTheme(data.currentOrg?.theme || '');
setCurOrg(data.currentOrg as CurrentOrg);
});