chore: reorder layout setup and debug org set after login

This commit is contained in:
Rotimi Best
2025-11-08 18:22:41 +01:00
parent b783940cee
commit aa42eb9c1f
+24 -29
View File
@@ -48,7 +48,7 @@
const getProfileDebounced = debounce(getProfile, 1000); const getProfileDebounced = debounce(getProfile, 1000);
onMount(() => { function pageSetup() {
console.log( console.log(
'Welcome to ClassroomIO, we are grateful you chose us.', 'Welcome to ClassroomIO, we are grateful you chose us.',
$page.url.host, $page.url.host,
@@ -56,26 +56,40 @@
data data
); );
if (browser) { $globalStore.isDark = localStorage.getItem('mode') === 'dark';
// Update theme - dark or light mode toggleBodyByMode($globalStore.isDark);
$globalStore.isDark = localStorage.getItem('mode') === 'dark';
toggleBodyByMode($globalStore.isDark);
if (data.isOrgSite && data.org?.theme) {
setTheme(data.org?.theme);
}
}
setupAnalytics(); setupAnalytics();
handleResize(); handleResize();
if (!data.isOrgSite || !data.org) return;
if ($currentOrg.siteName !== data.org.siteName) {
$globalStore.orgSiteName = data.orgSiteName;
$globalStore.isOrgSite = data.isOrgSite;
console.log('Setting current org to', data.org);
currentOrg.set(data.org);
// Setup internal analytics
initOrgAnalytics(data.orgSiteName);
}
setTheme(data.org?.theme);
}
$: console.log('Current org', $currentOrg);
onMount(() => {
pageSetup();
if (!hasSession() && !isPublicRoute($page.url?.pathname)) { if (!hasSession() && !isPublicRoute($page.url?.pathname)) {
console.log('No auth token and is not a public route, redirect to login', path); console.log('No auth token and is not a public route, redirect to login', path);
return goto('/login?redirect=/' + path); return goto('/login?redirect=/' + path);
} }
const { data: authListener } = supabase.auth.onAuthStateChange((event) => { const { data: authListener } = supabase.auth.onAuthStateChange((event) => {
// Log key events
console.log(`event`, event); console.log(`event`, event);
if (path.includes('reset')) { if (path.includes('reset')) {
@@ -83,10 +97,8 @@
return; return;
} }
// Skip Authentication
if (data.skipAuth) return; if (data.skipAuth) return;
// Authentication Steps
if (event === 'SIGNED_IN' || event === 'INITIAL_SESSION') { if (event === 'SIGNED_IN' || event === 'INITIAL_SESSION') {
getProfileDebounced({ getProfileDebounced({
path, path,
@@ -95,31 +107,14 @@
orgSiteName: data.orgSiteName orgSiteName: data.orgSiteName
}); });
} }
// else if (!['TOKEN_REFRESHED'].includes(event)) {
// console.log('not logged in, go to login');
// return goto('/login');
// }
}); });
console.log('BEFORE === Setting currentOrg in layout', data.org, $currentOrg);
if (data.isOrgSite && data.org && $currentOrg.siteName !== data.org.siteName) {
console.log('Setting currentOrg in layout');
$globalStore.orgSiteName = data.orgSiteName;
$globalStore.isOrgSite = data.isOrgSite;
currentOrg.set(data.org);
// Setup internal analytics
initOrgAnalytics(data.orgSiteName);
}
return () => { return () => {
console.log('unsubscribed'); console.log('unsubscribed');
authListener.subscription.unsubscribe(); authListener.subscription.unsubscribe();
}; };
}); });
$: console.log('$globalStore in root', $globalStore);
$: path = $page.url?.pathname?.replace('/', ''); $: path = $page.url?.pathname?.replace('/', '');
$: carbonTheme = $globalStore.isDark ? 'g100' : 'white'; $: carbonTheme = $globalStore.isDark ? 'g100' : 'white';
$: metaTags = merge(data.baseMetaTags, $page.data.pageMetaTags); $: metaTags = merge(data.baseMetaTags, $page.data.pageMetaTags);