We recommend splitting up your client-side implementation into four phases:
The recommended approach is to initially use a short-lived development token and then wire up production auth at a later stage.
Generate a temporary private/public key-pair (RS256) or shared key (HS256) for JWT signing and verification.
Add the key to your PowerSync Service configuration file, e.g.:
Generate a signed JWT. We have two options to get you started:
If you have a .yaml
configuration file and HS256 key, we recommending using the generate-token
script from the Test Client in the powersync-service repo, as described here Self-hosted Setup / Local Development. You need to clone this repo to use this option.
Alternatively:
Save the private key into a .env
file.
Generate a JWT, loading the .env
file and inputting a user UUID. See example script:
With the Diagnostics web app you can quickly inspect a user’s local database. By using this you can confirm that the PowerSync Service configuration and sync rules behave as expected without needing to set up authentication or app UI.
The app is currently available at https://diagnostics-app.powersync.com
It can also be run as a local standalone web app - see the README for instructions on running it locally.
Enter the generated token into the app’s sign in screen.
Enter your PowerSync Service endpoint (see the port number specified in your config file e.g. http://localhost:8080
).
Checkpoint:
Inspect your global bucket and synced table (from the PowerSync Service Setup section) in the diagnostics app — these should match the sync rules you defined previously.
Install the PowerSync client SDK in your app. Refer to the client-side installation instructions here: Client-Side Setup
Hardcode the development token you generated above in the fetchCredentials
method, which you’ll implement as part of Integrate with your Backend
Read about how authentication works in PowerSync here: Authentication Setup
If you are using Supabase or Firebase authentication, PowerSync can verify JWTs for users directly:
Under client_auth
in your config file, enable Supabase authentication:
For more details, see Supabase Auth.
Under client_auth
in your config file, add your Firebase JWKS URI and audience.
JWKS URI: https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com
JWT Audience: Your Firebase project ID
For more details, see Firebase Auth.
Refer to: Custom
PowerSync supports both RS256 and HS256. Insert your auth details into your configuration file: