2023-08-14 06:22:03 +01:00
|
|
|
// import { redirect } from '@sveltejs/kit';
|
|
|
|
|
import { blockedSubdomain } from '$lib/utils/constants/app';
|
2023-08-20 19:08:48 +00:00
|
|
|
import { getCurrentOrg } from '$lib/utils/services/org';
|
2023-08-21 10:10:11 +01:00
|
|
|
import { getSupabase, supabase } from '$lib/utils/functions/supabase';
|
|
|
|
|
|
|
|
|
|
if (!supabase) {
|
|
|
|
|
getSupabase();
|
|
|
|
|
}
|
2023-08-14 06:22:03 +01:00
|
|
|
|
|
|
|
|
/** @type {import('./$types').LayoutServerLoad} */
|
2023-08-20 19:08:48 +00:00
|
|
|
export const load = async ({ url, cookies }) => {
|
2023-08-14 06:22:03 +01:00
|
|
|
// if (url.hostname === 'classroomio.com') {
|
|
|
|
|
// throw redirect(301, 'https://about.classroomio.com');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
let response = {
|
|
|
|
|
orgSiteName: '',
|
|
|
|
|
isOrgSite: false,
|
2023-08-20 19:08:48 +00:00
|
|
|
skipAuth: false,
|
|
|
|
|
org: {}
|
2023-08-14 06:22:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const debugOrgLandingPage = cookies.get('debugOrgLandingPage');
|
|
|
|
|
const debugPlay = cookies.get('debugPlay');
|
|
|
|
|
const debugMode = debugOrgLandingPage === 'true';
|
|
|
|
|
console.log('debugOrgLandingPage', debugOrgLandingPage);
|
|
|
|
|
|
2023-08-16 04:24:24 +01:00
|
|
|
const matches = url.host.match(/([a-z 0-9 \-]+).*classroomio[.]com/);
|
2023-08-14 06:22:03 +01:00
|
|
|
const subdomain = matches?.[1] ?? '';
|
|
|
|
|
|
|
|
|
|
if (!blockedSubdomain.includes(subdomain)) {
|
|
|
|
|
const answer = Array.isArray(matches) ? !!subdomain && subdomain !== 'www' : false;
|
|
|
|
|
|
|
|
|
|
response.isOrgSite = debugMode || answer;
|
|
|
|
|
response.orgSiteName = debugMode ? 'codingdojo' : subdomain;
|
2023-08-21 10:10:11 +01:00
|
|
|
|
2023-08-20 19:08:48 +00:00
|
|
|
response.org = await getCurrentOrg(response.orgSiteName, true);
|
2023-08-14 06:22:03 +01:00
|
|
|
} else if (subdomain === 'play' || debugPlay === 'true') {
|
|
|
|
|
response.skipAuth = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
};
|