Skip to content

1.21.0 — offline sync with useLtOfflineSync

Choose a tag to compare

@kaihaase kaihaase released this 03 Nov 15:19
· 49 commits to main since this release

Feature release: useLtOfflineSync() reads and writes one model offline and syncs it with the @lenne.tech/nest-server sync module. It is opt-in: a project that does not enable it gets no new code and no changed behaviour.

Update

pnpm add @lenne.tech/nuxt-extensions@1.21.0

Do I need to do anything?

  • Not using offline sync: nothing. No peer range changed; better-auth stays at 1.7.12, in lock-step with @lenne.tech/nest-server. useLtAuth().signOut() behaves exactly as before.

  • To use offline sync, the API needs @lenne.tech/nest-server >= 12.2.0 with a sync model (@PersistedModel({ sync }) plus @SyncService). Then enable it in the app:

    // nuxt.config.ts
    ltExtensions: {
      sync: { enabled: true }, // basePath defaults to '/sync'
    },
    const notes = useLtOfflineSync<Note>('note');
    await notes.create({ title: 'Written offline' }); // shown at once, sent when online

    Options, return values and the conflict hook: README, Offline Sync.

  • Signing out without useLtAuth().signOut()? Then call flushLtSyncBeforeSignOut(userId) and deleteLtSyncDatabase() from @lenne.tech/nuxt-extensions/lib yourself. Otherwise the user's records stay on the device.

  • Service worker: never cache /sync or /iam responses.

Under the hood

The local data belongs to the signed-in user and tenant: another user's data is wiped before anything is shown, and every write of a sync run is checked against the user it started for. Signing out sends that user's unsent changes (at most 5 s) and then deletes the local database; an expired session deletes nothing, so the same changes go out after signing in again. Details: CHANGELOG