|
| 1 | +# PowerSync + Supabase Nuxt Demo: Todo List |
| 2 | + |
| 3 | +This is a demo application showcasing PowerSync integration with Nuxt 4 and Supabase. It demonstrates real-time data synchronization for a simple todo list application using PowerSync's official Nuxt module. |
| 4 | + |
| 5 | +## Setup Instructions |
| 6 | + |
| 7 | +Note that this setup guide has minor deviations from the [Supabase + PowerSync integration guide](https://docs.powersync.com/integration-guides/supabase-+-powersync). Below we refer to sections in this guide where relevant. |
| 8 | + |
| 9 | +### 1. Install dependencies |
| 10 | + |
| 11 | +In the repo root directory, use [pnpm](https://pnpm.io/installation) to install dependencies: |
| 12 | + |
| 13 | +```bash |
| 14 | +pnpm install |
| 15 | +pnpm build:packages |
| 16 | +``` |
| 17 | + |
| 18 | +### Quick Start: Local Development |
| 19 | + |
| 20 | +This demo can be started with local PowerSync and Supabase services. |
| 21 | + |
| 22 | +1. Install the [Supabase CLI](https://supabase.com/docs/guides/cli/getting-started) |
| 23 | + |
| 24 | +2. Copy the environment template: |
| 25 | + |
| 26 | + ```bash |
| 27 | + cp .env.template .env |
| 28 | + ``` |
| 29 | + |
| 30 | +3. Start Supabase: |
| 31 | + |
| 32 | + ```bash |
| 33 | + supabase start |
| 34 | + ``` |
| 35 | + |
| 36 | +4. Copy the values from the `supabase start` output into `.env`. Local Supabase uses JWKS for auth, so this demo configures PowerSync with `jwks_uri` and `audience: authenticated`: |
| 37 | + - `NUXT_PUBLIC_SUPABASE_ANON_KEY`: Use the **Publishable** key value |
| 38 | + - `PS_JWKS_URI`: Use `http://kong:8000/auth/v1/.well-known/jwks.json` when PowerSync runs in Docker on the Supabase network (default in step 5). This points PowerSync at local Supabase's JWKS so it can verify tokens. If Kong is not reachable from the container (e.g. custom network), try `http://host.docker.internal:54321/auth/v1/.well-known/jwks.json` on Docker Desktop for Mac/Windows. |
| 39 | + |
| 40 | +> [!NOTE] |
| 41 | +> `NUXT_PUBLIC_SUPABASE_ANON_KEY`: Use the Publishable key value (requires Supabase CLI v2.45.5+) |
| 42 | +
|
| 43 | +5. Start PowerSync: |
| 44 | + |
| 45 | + ```bash |
| 46 | + docker run \ |
| 47 | + -p 6060:6060 \ |
| 48 | + -e POWERSYNC_CONFIG_B64=$(base64 -i ./powersync.yaml) \ |
| 49 | + -e POWERSYNC_SYNC_RULES_B64=$(base64 -i ./sync-rules.yaml) \ |
| 50 | + --env-file ./.env \ |
| 51 | + --network supabase_network_nuxt-supabase-todolist \ |
| 52 | + --name powersync-nuxt journeyapps/powersync-service:latest |
| 53 | + ``` |
| 54 | + |
| 55 | +6. Run the demo: |
| 56 | + ```bash |
| 57 | + pnpm dev |
| 58 | + ``` |
| 59 | + |
| 60 | +Open [http://localhost:3000](http://localhost:3000) to use the app. |
| 61 | + |
| 62 | +### 2. Create project on Supabase and set up Postgres |
| 63 | + |
| 64 | +This demo app uses Supabase as its Postgres database and backend: |
| 65 | + |
| 66 | +1. [Create a new project on the Supabase dashboard](https://supabase.com/dashboard/projects). |
| 67 | +2. Go to the Supabase SQL Editor for your new project and execute the SQL statements in [`db/seed.sql`](db/seed.sql) to create the database schema, PowerSync replication role, and publication needed for PowerSync. |
| 68 | + |
| 69 | +**Note:** Before executing the SQL, make sure to update the `powersync_role` password in `db/seed.sql` (currently set to `'postgres_12345'`) to a secure password of your choice. |
| 70 | + |
| 71 | +**Important:** When connecting PowerSync to your Supabase database, you'll use the `powersync_role` credentials instead of the default Supabase connection string. This role has the necessary replication privileges and bypasses Row Level Security (RLS). |
| 72 | + |
| 73 | +### 3. Auth setup |
| 74 | + |
| 75 | +This app uses Supabase's email/password authentication. |
| 76 | + |
| 77 | +1. Go to "Authentication" -> "Providers" in your Supabase dashboard |
| 78 | +2. Ensure "Email" provider is enabled |
| 79 | +3. You can disable email confirmation for development by going to "Authentication" -> "Email Auth" and disabling "Confirm email" |
| 80 | + |
| 81 | +You'll need to create a user account when you first access the application. |
| 82 | + |
| 83 | +### 4. Set up PowerSync |
| 84 | + |
| 85 | +You can use either PowerSync Cloud or self-host PowerSync: |
| 86 | + |
| 87 | +- **PowerSync Cloud**: [Create a new project on the PowerSync dashboard](https://dashboard.powersync.com) and connect it to your Supabase database using the `powersync_role` credentials created in step 2. |
| 88 | +- **Self-hosting**: Follow the [self-hosting guide](https://docs.powersync.com/self-hosting/getting-started) to deploy your own PowerSync instance. |
| 89 | + |
| 90 | +The sync rules for this demo are provided in [`sync-rules.yaml`](sync-rules.yaml) in this directory. |
| 91 | + |
| 92 | +### 5. Set up local environment variables |
| 93 | + |
| 94 | +Create a `.env` file in this directory with the following variables: |
| 95 | + |
| 96 | +```bash |
| 97 | +NUXT_PUBLIC_SUPABASE_URL=your_supabase_url |
| 98 | +NUXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key |
| 99 | +NUXT_PUBLIC_POWERSYNC_URL=your_powersync_instance_url |
| 100 | +``` |
| 101 | + |
| 102 | +Replace the values with your actual credentials: |
| 103 | + |
| 104 | +- Get `NUXT_PUBLIC_SUPABASE_URL` and `NUXT_PUBLIC_SUPABASE_ANON_KEY` from your Supabase project settings under "Project Settings" -> "API" |
| 105 | +- Get `NUXT_PUBLIC_POWERSYNC_URL` from your PowerSync instance (Cloud dashboard or your self-hosted instance URL) |
| 106 | + |
| 107 | +### 6. Run the demo app |
| 108 | + |
| 109 | +In this directory, run the following to start the development server: |
| 110 | + |
| 111 | +```bash |
| 112 | +pnpm dev |
| 113 | +``` |
| 114 | + |
| 115 | +Open [http://localhost:3000](http://localhost:3000) with your browser to try out the demo. |
| 116 | + |
| 117 | +## Project Structure |
| 118 | + |
| 119 | +``` |
| 120 | +├── powersync/ |
| 121 | +│ ├── AppSchema.ts # PowerSync schema definition |
| 122 | +│ └── SuperbaseConnector.ts # Supabase connector implementation |
| 123 | +├── plugins/ |
| 124 | +│ └── powersync.client.ts # PowerSync plugin setup |
| 125 | +├── pages/ |
| 126 | +│ ├── index.vue # Main todo list page |
| 127 | +│ ├── login.vue # Login page |
| 128 | +│ └── confirm.vue # Auth confirmation page |
| 129 | +├── components/ |
| 130 | +│ └── AppHeader.vue # Header component |
| 131 | +├── db/ |
| 132 | +│ └── seed.sql # Database setup SQL |
| 133 | +├── powersync.yaml # PowerSync server configuration |
| 134 | +├── sync-rules.yaml # PowerSync sync rules |
| 135 | +└── nuxt.config.ts # Nuxt configuration |
| 136 | +``` |
| 137 | + |
| 138 | +## Learn More |
| 139 | + |
| 140 | +- [PowerSync Documentation](https://docs.powersync.com/) |
| 141 | +- [Supabase Documentation](https://supabase.com/docs) |
| 142 | +- [Nuxt Documentation](https://nuxt.com/) |
0 commit comments