5.2 KiB
| name | description | metadata | ||
|---|---|---|---|---|
| onboarding-supabase | Step-by-step onboarding recipe for any app using Supabase with PowerSync Cloud — orchestrates the correct sequence and points to canonical references for each step |
|
Supabase + PowerSync Cloud Onboarding
Load this when onboarding an app onto PowerSync Cloud with a Supabase backend.
Use this recipe when onboarding any app onto PowerSync Cloud with a Supabase backend. This works for all platforms (web, React Native, Flutter, Kotlin, Swift, .NET, etc.).
CLI-first. See references/powersync-cli.md. Fall back to the dashboard only if the CLI is unavailable or the operator explicitly prefers it.
Required Inputs
Collect before editing app code:
- Whether the PowerSync Cloud instance already exists
- PowerSync instance URL (if instance exists)
- Project ID and instance ID (if using CLI with existing instance)
- Supabase Postgres connection string (if source DB connection not yet configured)
PS_ADMIN_TOKENor willingness to runpowersync login(Cloud PAT only)
Only ask for the Postgres connection string when you reach the service configuration step.
Note: The Supabase CLI (supabase init, supabase link) does not create a new online Supabase project — it only scaffolds local config or links to an existing one.
Workflow
Follow this sequence exactly. Do not skip ahead to app code.
Phase 1: Service Setup
-
Confirm the path. PowerSync Cloud + Supabase + your platform.
-
Write credentials to
.envimmediately. As soon as Supabase project details are available, writeSUPABASE_URL,SUPABASE_ANON_KEY,PS_DATABASE_URI, andPOWERSYNC_URLto.env. Bothservice.yaml(via!envtags) and app code depend on these values. For how to getPOWERSYNC_URL, seereferences/powersync-cli.md§ "Getting POWERSYNC_URL". -
Run the Supabase publication SQL. The publication must exist before PowerSync connects to the database. See
references/supabase-auth.md§ "Supabase Database Setup" for the exact SQL. Present it to the operator and ask them to confirm. -
Scaffold and configure PowerSync.
- New instance (CLI):
powersync init cloud→ edit config →powersync link cloud --create --project-id=<id>→ deploy - New instance (Dashboard): Create project/instance → connect database → deploy sync config → enable Supabase Auth
- Existing instance (CLI):
powersync pull instance --project-id=<id> --instance-id=<id>→ edit → deploy
See
references/powersync-cli.mdfor full CLI workflow. Never runpowersync pull instanceafter editing local config without backing up first. - New instance (CLI):
-
Configure service.yaml. See
references/powersync-service.md§ "Minimal Cloud service.yaml Examples" for the Cloud + Supabase Auth template. -
Configure client auth. See
references/supabase-auth.mdfor all Supabase auth options (new signing keys, legacy HS256, local Supabase, manual JWKS). -
Generate sync config. Load
references/sync-config.md. Use Sync Streams withconfig: edition: 3. -
Deploy config (prefer CLI):
powersync deploy service-config powersync deploy sync-config
Phase 2: Backend Readiness Gate
Do not proceed to app code until all items are verified:
- PowerSync instance exists and is running
- Source database connection is configured
- Supabase publication exists for synced tables
- Sync config is deployed with
config: edition: 3 - Client auth is configured for Supabase
- All credentials and URLs are in
.env
If any item is missing, finish it before writing app code.
Phase 3: App Integration
Only after Phase 2 is complete.
-
Install SDK packages. Load the SDK reference file for your platform — see the SDK table in
SKILL.md. -
Define the client schema. Generate from deployed sync config:
powersync generate schema --output=ts --output-path=./src/schema.tsOr write manually — but never define the
idcolumn (it is automatic). -
Implement the backend connector. See
references/supabase-auth.md§ "fetchCredentials()" and § "uploadData()" for complete implementations including error handling strategy.Auth prerequisite:
fetchCredentials()requires an active Supabase session. Calldb.connect(connector)only after the user has signed in. For apps without a sign-in screen, enable anonymous auth in Supabase Dashboard → Authentication → Providers → Anonymous. -
Initialize PowerSync and connect.
connect()is fire-and-forget — usewaitForFirstSync()if you need readiness.- Use
disconnectAndClear()on logout or user switch.
-
Development tokens (optional, for testing without user auth): After deploying, run
powersync generate token --subject=<user-id>to get a short-lived JWT. On PowerSync Cloud, this works immediately after deploy — no extraclient_authconfig needed. Do not use dev tokens in production. -
Switch reads to local SQLite and test offline behavior.
If the App Is Stuck on Syncing...
See references/powersync-debug.md § "First Response When the UI Is Stuck on Syncing..." — check backend readiness before inspecting frontend code.