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(); }