From 94512f15219f9a7073bbd5281d56d09f70fe1fcc Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sat, 14 Feb 2026 16:27:53 +1300 Subject: [PATCH] Fixed isLoggedIn check --- materialious/src/routes/(app)/+layout.svelte | 18 ++++++++++-------- .../src/routes/api/user/isLoggedIn/+server.ts | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/materialious/src/routes/(app)/+layout.svelte b/materialious/src/routes/(app)/+layout.svelte index f65d74e9..2aefed80 100644 --- a/materialious/src/routes/(app)/+layout.svelte +++ b/materialious/src/routes/(app)/+layout.svelte @@ -191,13 +191,13 @@ async function logout() { if (isYTBackend()) { await clearFeedYTjs(); - - if (isOwnBackend()?.internalAuth) { - rawMasterKeyStore.set(undefined); - fetch('/api/user/logout', { method: 'DELETE' }); - } } + if (isOwnBackend()?.internalAuth) { + fetch('/api/user/logout', { method: 'DELETE' }); + } + + rawMasterKeyStore.set(undefined); authStore.set(null); goto(resolve('/', {})); } @@ -260,9 +260,11 @@ } if ($rawMasterKeyStore) { - fetch('/api/user/isLoggedIn', { method: 'GET', credentials: 'same-origin' }).catch(() => { - logout(); - }); + fetch('/api/user/isLoggedIn', { method: 'GET', credentials: 'same-origin' }) + .then((resp) => { + if (!resp.ok) logout(); + }) + .catch(logout); } resetScroll(); diff --git a/materialious/src/routes/api/user/isLoggedIn/+server.ts b/materialious/src/routes/api/user/isLoggedIn/+server.ts index cef444e0..f43a8ad7 100644 --- a/materialious/src/routes/api/user/isLoggedIn/+server.ts +++ b/materialious/src/routes/api/user/isLoggedIn/+server.ts @@ -1,3 +1,4 @@ +import { getUser } from '$lib/server/user.js'; import { error } from '@sveltejs/kit'; export async function GET({ locals }) { @@ -5,5 +6,7 @@ export async function GET({ locals }) { throw error(401); } + await getUser(locals.userId); + return new Response(); }