chore: debug cookies better

This commit is contained in:
Rotimi Best
2026-03-12 08:57:39 +01:00
parent 14a81793ef
commit 30c157468e
5 changed files with 26 additions and 8 deletions
@@ -111,6 +111,7 @@ class AppInitApi extends BaseApi {
const redirect = page.url.searchParams.get('redirect');
if (redirect) {
console.log('redirecting to', redirect);
// goto redirect won't accept dynamic url so we need to use window.location.href
window.location.href = redirect;
return;
@@ -118,6 +119,7 @@ class AppInitApi extends BaseApi {
// This allows you to be on the landing page of an organization site and not be redirected
if (isOrgSite && window.location.pathname === '/') {
console.log('no redirect is needed');
return;
}
@@ -130,11 +132,13 @@ class AppInitApi extends BaseApi {
if (isCloud) {
const shouldRedirectToOnboarding = !userHasOrganizations && !isOrgSite;
if (shouldRedirectToOnboarding) {
console.log('cloud: redirecting to onboarding');
return goto(resolve(`/onboarding`, {}));
}
} else {
// Self-hosted: when user has no orgs, route to /onboarding
if (!userHasOrganizations) {
console.log('self-hosted: redirecting to onboarding');
return goto(resolve(`/onboarding`, {}));
}
}
@@ -142,6 +146,7 @@ class AppInitApi extends BaseApi {
if (!shouldRedirectOnAuth(page.url.pathname)) return;
const shouldGoToLMS = isCloud ? isOrgSite || !!isStudent : !!isStudent;
console.log('redirecting to', shouldGoToLMS ? 'lms' : 'org');
return shouldGoToLMS ? this.goToLMS() : this.goToOrg();
}
@@ -0,0 +1,13 @@
import type { Cookies } from '@sveltejs/kit';
/**
* Returns the classroomio cookie string for API/auth requests.
* Filters cookies whose names include "classroomio" and joins them as `name=value; ...`.
*/
export function getCioCookieString(cookies: Cookies): string {
return cookies
.getAll()
.filter((c) => c.name.includes('classroomio'))
.map((c) => `${c.name}=${c.value}`)
.join('; ');
}
@@ -7,6 +7,7 @@ import { get } from 'svelte/store';
import { currentOrg } from '$lib/utils/store/org';
import type { Cookies } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';
import { getCioCookieString } from '$lib/utils/functions/cookies';
export const getRequestBaseUrl = () => {
if (typeof window === 'undefined') {
@@ -221,11 +222,7 @@ export function getApiHeaders(
cookies: Cookies,
orgId?: string
): { headers: { cookie: string; 'cio-org-id'?: string } } {
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);
console.log('cookies', cookies.getAll());