mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
fix(offline): a missing driving-settings row no longer discards the trip bundle
syncTrip read the roadtrip preferences before writing anything and rethrew everything but a 404. That read has an offline fallback which throws a bare Error when there is no cached row, which is the state a first sync is in and the state a logout leaves behind, so the whole downloaded bundle for that trip was dropped while the run still counted it. Settings reported "N trips stored" over an empty database, and the trips were gone the moment the connection was. The read moved to the end and is never fatal now: it belongs to an optional addon and the addon answers 404 when it is off. Two things that fed it, from the same trace. A sync run started on navigator.onLine alone, so work-offline downloaded over the real connection while every repo read answered from cache. And work-offline itself survived a logout, in localStorage, while step six of the same logout deleted the database it reads from, so the next account came up believing it was offline with nothing to be offline with. Also in this pass: deleting a hotel booking released its day stop after deleting the booking row, which now clears the stop's pointer by trigger. The release goes first, or the stop stands with nothing left to reach it.
This commit is contained in:
@@ -7,6 +7,7 @@ import { getApiErrorMessage } from '../types'
|
||||
import { tripSyncManager } from '../sync/tripSyncManager'
|
||||
import { reopenForUser, deleteCurrentUserDb } from '../db/offlineDb'
|
||||
import { setAuthed } from '../sync/authGate'
|
||||
import { setForcedOffline } from '../sync/networkMode'
|
||||
import { registerSyncTriggers, unregisterSyncTriggers } from '../sync/syncTriggers'
|
||||
import { useSystemNoticeStore } from './systemNoticeStore.js'
|
||||
import { clearAppearanceSnapshot } from '../theme/applyAppearance'
|
||||
@@ -252,6 +253,11 @@ export const useAuthStore = create<AuthState>()(
|
||||
// browser language is one TREK ships, so otherwise the next user here stays
|
||||
// in the previous account's language, launch after launch.
|
||||
forgetServerLanguage()
|
||||
// And work-offline, for the same reason with sharper teeth: the switch lives
|
||||
// in localStorage, step 6 below deletes the offline database it reads from,
|
||||
// and the next account would come up believing it is offline over a working
|
||||
// connection, with nothing cached to answer from.
|
||||
setForcedOffline(false)
|
||||
// 4. Tell server to clear the httpOnly cookie (best-effort).
|
||||
await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' }).catch(() => {})
|
||||
// 5. Clear service worker caches containing sensitive data.
|
||||
|
||||
Reference in New Issue
Block a user