A template Vite, TS, React, PowerSync and Supabase project to get you started quickly with building offline-first applications with PowerSync and Supabase.
You have 3 options to get started with this template. We recommend using the first option for a quick start.
npx degit powersync-product-success/vite-react-ts-powersync-supabase vite-react-ts-powersync-supabase- Clone the repository directly and install dependencies:
git clone https://github.com/powersync-product-success/vite-react-ts-powersync-supabase.gitAfter cloning the repository, navigate to the project directory and install the dependencies:
cd vite-react-ts-powersync-supabase
npm install
npm run devFollow these steps to set up your backend with Supabase and PowerSync (Or you can follow the guide).
- Create a new project on the Supabase dashboard.
- Go to the Supabase SQL Editor for your new project and execute the SQL statements in
database.pgsqlto create the database schema, database functions, and publication needed for PowerSync. - Enable "anonymous sign-ins" for the project here (demo specific)
If you prefer using the Supabase CLI, you can set up your project as follows:
- Setup a local project directory
mkdir my-project cd my-project - Install Supabase cli
npm install supabase --save-dev1 - Login to your Supabase Account
npx supabase login - Initialize your project
npx supabase init - Enable "anonymous sign-ins" for the project here
- Copy your project ID from the Supabase dashboard here
- Link your local project
npx supabase link --project-ref <project-id> - Create your
npx supabase migration new create_powersync_tablesand copy the contents ofdatabase.pgsqlinto the newly created migration file in thesupabase/migrationsdirectory. - Push your tables to the cloud db
npx supabase db push
You can set up your PowerSync instance using either the Dashboard or CLI approach:
Option 1: Using PowerSync CLI
This PowerSync CLI only works with PowerSync Cloud instances. The CLI currently does not support self-hosted PowerSync instances.
If you don't have a PowerSync account yet, sign up here.
-
Get your Personal Access Token: - Go to the PowerSync dashboard - Press
Ctrl + Shift + P(orCmd + Shift + Pon Mac) - Search for "Create Personal Access Token" - Give it "owner" policy and a descriptive label - Copy the generated token -
Initialize the CLI and authenticate:
bash npx powersync initPaste your Personal Access Token when prompted. -
Create a new PowerSync instance:
bash npx powersync instance createFollow the prompts to configure: - Instance name (e.g., "supabase-staging") - Region (e.g., "EU") - Database connection details from your Supabase project (use the direct connection, not pooling) - When asked about Supabase auth, answer: -? Are you using Supabase auth? Yes-? Do you want to add audiences? No -
Deploy sync rules:
bash npx powersync instance sync-rules deploy -f sync-rules.yamlAfter deploying sync rules via CLI, the changes might not be reflected in the dashboard. If you want to see them in the dashboard, simply copy the contents of your
sync-rules.yamlfile and paste them into the dashboard's sync-rules editor, then redeploy.
If you prefer using the web interface:
-
In the PowerSync dashboard, create a new PowerSync instance: - Right-click on 'PowerSync Project' in the project tree on the left and click "Create new instance" - Pick a name for the instance e.g. "Yjs Demo Test" and proceed.
-
In the "Edit Instance" dialog that follows, click on the "Connections" tab: - Click on the "+" button to create a new database connection. - Input the credentials from the project you created in Supabase. In the Supabase dashboard, under your project you can go to "Project Settings" and then "Database" and choose "URI" under "Connection string", untick the "Use connection pooling" option to use the direct connection, and then copy & paste the connection string into the PowerSync dashboard "URI" field, and then enter your database password at the "Password" field. - Click the "Test connection" button and you should see "Connection success!"
-
Click on the "Credentials" tab of the "Edit Instance" dialog: - Tick the "Use Supabase Auth" checkbox and configure the JWT secret. - Click "Save" to save all the changes to your PowerSync instance. The instance will now be deployed — this may take a minute or two.
The sync rules are already deployed if you followed the CLI setup steps above.
- Open the
sync-rules.yamlin this repo and copy the contents. - In the PowerSync dashboard, paste that into the 'sync-rules.yaml' editor panel.
- Click the "Deploy sync rules" button and select your PowerSync instance from the drop-down list.