From d0e90b30e4d05d726d2fe74f8c0180e54293f684 Mon Sep 17 00:00:00 2001 From: Rotimi Best Date: Sun, 3 Dec 2023 16:29:27 +0300 Subject: [PATCH] improve layout.server --- apps/dashboard/src/routes/+layout.server.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/apps/dashboard/src/routes/+layout.server.ts b/apps/dashboard/src/routes/+layout.server.ts index 59dda199..6884e4f6 100644 --- a/apps/dashboard/src/routes/+layout.server.ts +++ b/apps/dashboard/src/routes/+layout.server.ts @@ -12,29 +12,22 @@ interface LoadOutput { orgSiteName: string; isOrgSite: boolean; skipAuth: boolean; - org: CurrentOrg; + org: CurrentOrg | null; } export const load = async ({ url, cookies }): Promise => { - // if (url.hostname === 'classroomio.com') { - // throw redirect(301, 'https://about.classroomio.com'); - // } - - let response: LoadOutput = { + const response: LoadOutput = { orgSiteName: '', isOrgSite: false, skipAuth: false, - org: { - theme: '' - } + org: null }; const _orgSiteName = cookies.get('_orgSiteName'); const debugPlay = cookies.get('debugPlay'); const debugMode = _orgSiteName && _orgSiteName !== 'false'; - console.log('_orgSiteName', _orgSiteName); - const matches = url.host.match(/([a-z 0-9 \-]+).*classroomio[.]com/); + const matches = url.host.match(/([a-z 0-9 -]+).*classroomio[.]com/); const subdomain = matches?.[1] ?? ''; if (!blockedSubdomain.includes(subdomain)) { @@ -42,7 +35,7 @@ export const load = async ({ url, cookies }): Promise => { response.isOrgSite = debugMode || answer; response.orgSiteName = debugMode ? _orgSiteName : subdomain; - response.org = await getCurrentOrg(response.orgSiteName, true); + response.org = (await getCurrentOrg(response.orgSiteName, true)) || null; } else if (subdomain === 'play' || debugPlay === 'true') { response.skipAuth = true; }