Skip to content

Updated practices for VFS - #61

Merged
michaelbarnes merged 6 commits into
mainfrom
feat/modernize-supabase-and-storage
Jul 8, 2026
Merged

Updated practices for VFS#61
michaelbarnes merged 6 commits into
mainfrom
feat/modernize-supabase-and-storage

Conversation

@michaelbarnes

Copy link
Copy Markdown
Contributor

Description

This PR adds changes that address best practices when handling VFS for different platforms and browsers, focusing on how to handle cases for Safari on desktop and mobile.

AI Disclosure

Claude Opus 4.8 was used to generate the helper functions. All changes were tested and verified by myself.

michaelbarnes and others added 6 commits July 7, 2026 15:03
Replace the legacy Supabase anon API key with the new publishable key
(sb_publishable_...) throughout the app and templates:

- SupabaseConnector reads VITE_SUPABASE_PUBLISHABLE_KEY (config field
  renamed supabaseAnonKey -> supabaseKey)
- .env.local.template / .env.cloud.template / README updated to the
  publishable key naming and guidance

Newer Supabase (CLI and new projects) signs user tokens with asymmetric
ES256 JWT signing keys, which the HS256 shared-secret config rejected
(PSYNC_S2101). Point PowerSync at the Supabase Auth JWKS endpoint so it
validates ES256 tokens by KID, keep the HS256 secret as a fallback, and
declare the "authenticated" audience:

- docker/powersync.yaml: add jwks_uri (via PS_SUPABASE_JWKS_URI) and
  audience: [authenticated]
- env templates: add PS_SUPABASE_JWKS_URI (http://kong:8000/... on the
  shared Docker network)
- README: note the asymmetric-key consideration for cloud instances

Verified locally end to end: anonymous sign-in ES256 token is accepted
by /write-checkpoint2.json and /sync/stream (HTTP 200), bogus tokens
still 401.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Choose the PowerSync SQLite VFS based on the runtime environment instead of
always attempting OPFS:

- Add isMobile() and isSafari() detection (handles iPadOS reporting as macOS
  and Chromium/Firefox carrying "Safari" in their UA).
- Add isOPFSUsable(): an async probe that opens a SyncAccessHandle inside a
  throwaway Worker to confirm OPFS actually works. Safari Private Browsing
  exposes the OPFS API but fails this call, so the probe catches it. Non-Safari
  browsers skip the probe. Falls back safely on timeout/error.
- pickVFS() now falls back to IndexedDB (IDBBatchAtomicVFS) for: unusable OPFS
  (incl. Safari Private Browsing), mobile Safari, and desktop Safari multi-tab.
- Disable multi-tab in Safari Private Browsing (isSafariPrivate); other
  IndexedDB cases keep multi-tab.

Also drop the now-unused SyncClientImplementation import (the Rust sync client
is the default in current PowerSync, so the explicit clientImplementation is no
longer needed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@michaelbarnes
michaelbarnes merged commit 12e5b31 into main Jul 8, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant