Skip to main content
On this route, uploadData() uses the Supabase client SDK to send each queued change to Supabase’s Data API, which is built on PostgREST. You don’t deploy a separate write endpoint: Supabase’s grants and row-level security (RLS) policies decide which writes each user can make. The Supabase guide and the Supabase demo apps use this route.

Add Grants and RLS Policies

Requests from a signed-in user run as Supabase’s authenticated role, so your grants and RLS policies for that role must allow every write that your app uploads. Grant the authenticated role access to every table that your app writes to, enable RLS on each one, and add a policy for each operation that your app uploads:
  • A PUT is an upsert, so it needs INSERT and UPDATE policies, and the existing row must be visible to the user.
  • A PATCH needs an UPDATE policy, and a DELETE needs a DELETE policy.
Use WITH CHECK so that users can’t assign rows to someone else. For example:
If authenticated has grants on a table that has RLS disabled, any signed-in user can write any row in it. Check every table in the schemas that your app writes to, not only the tables that you sync.
If a policy or a missing grant denies a write, the example connectors drop it. See How the Connector Handles Errors.

Transactions Are Not Atomic

The Supabase client SDK has no transaction support. uploadData() sends each change in a transaction as a separate request, and each request commits on its own. If one change in a transaction fails, the changes before it stay in the database. For example, an app creates a list and its first item in one local transaction. If the insert of the item fails, the list is still created in Supabase. If your app needs all changes in a transaction to be applied together or not at all, you have two options:
  • Use the Edge Function route, which runs the reference write implementation as a Supabase Edge Function and applies each transaction atomically.
  • Write a Postgres function that applies the whole transaction, and call it from uploadData() with the Supabase client’s rpc() method.

How the Connector Handles Errors

The example connectors are based on the Supabase demo apps, such as the React demo’s SupabaseConnector.ts. Their uploadData() checks the Postgres error code that Supabase returns: When the connector marks the transaction complete after an error, it drops the failed change and every change after it in the same transaction. These changes become rejected writes. The app’s local data reverts after the next sync. The error appears only in the app’s logs. For the causes of 42501, see Uploads Fail With Error 42501. The connector retries every other error, including errors that can never succeed, such as PGRST204 for a column that doesn’t exist in Supabase. Such a transaction becomes a blocked transaction and holds back every later write until you fix the cause. Check the app’s logs for repeated upload errors. To reduce the number of requests, you can merge consecutive changes to the same table into one request. See Improve Supabase Connector.

Connector Examples

Copy the connector for your SDK into your app. Each one passes the Supabase Auth session token to PowerSync and uploads writes with the Supabase client SDK. There is no Supabase connector for Rust. The connectors read your Supabase project URL, your Supabase anon key, and your PowerSync instance URL from your app’s configuration, such as environment variables. Set those values in your app, then pass the connector to connect() in place of your current connector.
PowerSyncConnector.js