🐛 Recover the app when the session expires

A 401 mid-session made the PocketBase SDK drop the auth store, while
session.userId and the gate of the layout stayed set: the user remained
in the app, every round failed, /login was bounced back and a token-less
pull was even taken for a successful round.

The sync layer now ends the session through an onSessionExpired hook
when a round fails with 401 or finds the auth store cleared, and reports
no round as synced without a valid auth store. The session module tries
one token refresh before it clears the session, and the layout resolves
the gate again whenever the auth store is no longer valid, so the user
lands on the login page and the next sign-in brings the data back.
This commit is contained in:
2026-12-01 19:04:06 +01:00
parent e630f9fd66
commit d750b8c3c9
7 changed files with 194 additions and 13 deletions
+2 -2
View File
@@ -3,13 +3,13 @@
import { goto } from '$app/navigation';
import { page } from '$app/state';
import { pendingCount, status, syncNow } from '$lib/db.svelte';
import { resolveGate, safeNext, session } from '$lib/session.svelte';
import { gateStale, resolveGate, safeNext, session } from '$lib/session.svelte';
let { children } = $props();
let gate = $state<'login' | 'app' | null>(null);
async function route() {
if (!session.userId || gate === 'login') gate = await resolveGate();
if (gateStale(gate)) gate = await resolveGate();
const path = page.url.pathname;
if (gate === 'app') {
if (path === '/' || path === '/login') await goto(safeNext(page.url), { replaceState: true });