Standard Supabase Auth
These examples show how to implementfetchCredentials() in your client-side backend connector to get the Supabase JWT from the Supabase Client Library:
Anonymous Sign-Ins
This examples shows use of Supabase’ssignInAnonymously() and then the implementation of fetchCredentials() to get the JWT from the Supabase Client Library:
Fully Custom Auth
This example shows how to implement Supabase Edge Functions to generate custom JWTs for PowerSync (either for signed-in users or anonymous users) as well as expose a JWKS endpoint:External Auth Providers
We’ve heard from the community that Supabase’s support for third-party auth providers works with PowerSync, but we don’t have any examples for this yet.Supabase JWT Signing Keys
Supabase supports two types of JWT signing keys:
PowerSync supports both methods. Which configuration you need depends on your Supabase project’s JWT settings and your PowerSync deployment type.
To check which signing keys your Supabase project uses, go to Project Settings > JWT in your Supabase Dashboard.
PowerSync Cloud
When using PowerSync Cloud with a Supabase-hosted database, PowerSync can auto-detect your Supabase project from the database connection string and configure authentication automatically.- New JWT Signing Keys (Recommended)
- Legacy JWT Signing Keys
- Manual JWKS Configuration
Using New JWT Signing Keys
This is the recommended approach for Supabase projects using asymmetric JWT signing keys.- In the PowerSync Dashboard, select your project and instance and go to the Client Auth view.
- Enable the Use Supabase Auth checkbox.
- Leave the Supabase JWT Secret field empty (it’s not needed for new keys).
- Click Save and Deploy.
PowerSync auto-detects your Supabase project from the database connection string and configures the JWKS URI (
https://<project-ref>.supabase.co/auth/v1/.well-known/jwks.json) and JWT audience (authenticated) automatically.Self-Hosted PowerSync
For self-hosted PowerSync instances, configure authentication in yourservice.yaml.
- New JWT Signing Keys (Recommended)
- Legacy JWT Signing Keys
- Manual JWKS Configuration
Using New JWT Signing Keys
When using a standard Supabase connection string, PowerSync auto-detects your Supabase project:- JWKS URI:
https://<project-ref>.supabase.co/auth/v1/.well-known/jwks.json - Audience:
authenticated
Migrating from Legacy to New JWT Signing Keys
If you’re migrating your Supabase project from legacy JWT signing keys to the new asymmetric keys:Step 1: Complete the Supabase Migration
Follow all steps in Supabase’s JWT signing keys migration guide, including the “Rotate to asymmetric JWTs” step.Step 2: Update PowerSync Configuration
For PowerSync Cloud and self-hosted with standard Supabase connections:- No changes required. PowerSync auto-detects and uses the new JWKS endpoint.
- If you previously provided a legacy JWT secret, you can remove it (it’s no longer needed).
- Ensure your JWKS URI (
jwks_uri) points to your Supabase JWKS endpoint. - Verify the
authenticatedJWT Audience (audience) is configured.
Step 3: Clear Cached Tokens
Have all users sign out and sign back in. This ensures they receive new tokens signed with the asymmetric keys.Troubleshooting
Debugging error codes:PSYNC_S2101: Could not find an appropriate key in the keystore
This error indicates PowerSync cannot verify the JWT signature. Common causes:
PSYNC_S2105: JWT payload is missing a required claim “aud”
This error occurs when using manual JWKS configuration without specifying an audience. Add authenticated to your audience configuration.
Auto-Detection Not Working
If PowerSync logs this warning:Sync Streams
The Supabase user UUID will be available as:auth.user_id()in Sync Streams.request.user_id()in Sync Rules