refactor: streamline cookie handling in session data retrieval and improve logging in stats fetching

This commit is contained in:
Rotimi Best
2026-03-12 09:21:04 +01:00
parent 30c157468e
commit 3a2487a322
2 changed files with 4 additions and 7 deletions
@@ -1,21 +1,18 @@
import type { Cookies } from '@sveltejs/kit';
import { authServerClient } from './server';
import { classroomio } from '$lib/utils/services/api';
import { getCioCookieString } from '$lib/utils/functions/cookies';
import { getRequestBaseUrl } from '$lib/utils/services/api';
export const getSessionData = async (cookies: Cookies): Promise<App.Locals | null> => {
try {
const cioCookies = cookies
.getAll()
.filter((c) => c.name.includes('classroomio'))
.map((c) => `${c.name}=${c.value}`)
.join('; ');
const cioCookies = getCioCookieString(cookies);
console.log('cioCookies', cioCookies);
if (!cioCookies) return null;
const locals = await getThroughAuthClient(cioCookies);
console.log('has locals', !!locals);
if (!locals) return null;
// This will always be true because if we don't have classroomio cookies, we won't be able to this line of code.
@@ -25,7 +25,7 @@ export const load = async ({ params, parent, cookies }) => {
}
try {
console.log('fetching stats', cookies);
console.log('fetching stats');
const statsResponse = await classroomio.dash.stats.$get({ query: { siteName } }, getApiHeaders(cookies, orgId));
const statsData = await statsResponse.json();
cache[orgId] = statsData.success ? statsData.data : null;