PowerSync allows generating temporary development tokens for authentication. This is useful for developers who want to get up and running quickly, without a full custom auth implementation. This may also be used to generate a token for a specific user to debug issues.

Generating a Development Token:

PowerSync Cloud - Dashboard:

  1. Enable setting: The “Enable development tokens” setting must be set on the PowerSync instance. This should be enabled by default for new instances. It can be set in the instance’s config (In the PowerSync dashboard: Edit instance -> Client Auth).
  1. Generate token: Call the “Generate development token” action for your instance. In the PowerSync dashboard, this can be done via the command palette (CMD+SHIFT+P / SHIFT+SHIFT), or by selecting it from an instance’s options (right-click on an instance for options).
  1. Enter token subject / user ID: This is the ID of the user you want to authenticate and is used in sync rules as request.user_id() (previously, token_parameters.user_id)
  1. Copy the generated token. Note that these tokens expire after 12 hours.

Self-hosted Setup / Local Development

For self-hosted local development, the powersync-service test client contains a script to generate a development token, given a .yaml config file with an HS256 key. Run the following command:

node dist/bin.js generate-token --config path/to/powersync.yaml --sub test-user

Usage

To use the temporary development token, update the fetchCredentials() function in your backend connector to return the generated token (see Integrate with your Backend for more information).

Example:

return PowerSyncCredentials(
        endpoint: AppConfig.powersyncUrl,
        token: 'temp-token-here');