|
| 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 | +### 2. Create project on Supabase and set up Postgres |
| 19 | + |
| 20 | +This demo app uses Supabase as its Postgres database and backend: |
| 21 | + |
| 22 | +1. [Create a new project on the Supabase dashboard](https://supabase.com/dashboard/projects). |
| 23 | +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. |
| 24 | + |
| 25 | +**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). |
| 26 | + |
| 27 | +### 3. Auth setup |
| 28 | + |
| 29 | +This app uses Supabase's email/password authentication. |
| 30 | + |
| 31 | +1. Go to "Authentication" -> "Providers" in your Supabase dashboard |
| 32 | +2. Ensure "Email" provider is enabled |
| 33 | +3. You can disable email confirmation for development by going to "Authentication" -> "Email Auth" and disabling "Confirm email" |
| 34 | + |
| 35 | +You'll need to create a user account when you first access the application. |
| 36 | + |
| 37 | +### 4. Set up PowerSync |
| 38 | + |
| 39 | +You can use either PowerSync Cloud or self-host PowerSync: |
| 40 | + |
| 41 | +- **PowerSync Cloud**: [Create a new project on the PowerSync dashboard](https://powersync.journeyapps.com/) and connect it to your Supabase database using the `powersync_role` credentials created in step 2. |
| 42 | +- **Self-hosting**: Follow the [self-hosting guide](https://docs.powersync.com/self-hosting/getting-started) to deploy your own PowerSync instance. |
| 43 | + |
| 44 | +The sync rules for this demo are provided in [`sync-rules.yaml`](sync-rules.yaml) in this directory. |
| 45 | + |
| 46 | +### 5. Set up local environment variables |
| 47 | + |
| 48 | +Create a `.env` file in this directory with the following variables: |
| 49 | + |
| 50 | +```bash |
| 51 | +NUXT_PUBLIC_SUPABASE_URL=your_supabase_url |
| 52 | +NUXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key |
| 53 | +NUXT_PUBLIC_POWERSYNC_URL=your_powersync_instance_url |
| 54 | +``` |
| 55 | + |
| 56 | +Replace the values with your actual credentials: |
| 57 | +- Get `NUXT_PUBLIC_SUPABASE_URL` and `NUXT_PUBLIC_SUPABASE_ANON_KEY` from your Supabase project settings under "Project Settings" -> "API" |
| 58 | +- Get `NUXT_PUBLIC_POWERSYNC_URL` from your PowerSync instance (Cloud dashboard or your self-hosted instance URL) |
| 59 | + |
| 60 | +### 6. Run the demo app |
| 61 | + |
| 62 | +In this directory, run the following to start the development server: |
| 63 | + |
| 64 | +```bash |
| 65 | +pnpm dev |
| 66 | +``` |
| 67 | + |
| 68 | +Open [http://localhost:3000](http://localhost:3000) with your browser to try out the demo. |
| 69 | + |
| 70 | +## Project Structure |
| 71 | + |
| 72 | +``` |
| 73 | +├── powersync/ |
| 74 | +│ ├── AppSchema.ts # PowerSync schema definition |
| 75 | +│ └── SuperbaseConnector.ts # Supabase connector implementation |
| 76 | +├── plugins/ |
| 77 | +│ └── powersync.client.ts # PowerSync plugin setup |
| 78 | +├── pages/ |
| 79 | +│ ├── index.vue # Main todo list page |
| 80 | +│ ├── login.vue # Login page |
| 81 | +│ └── confirm.vue # Auth confirmation page |
| 82 | +├── components/ |
| 83 | +│ └── AppHeader.vue # Header component |
| 84 | +├── db/ |
| 85 | +│ └── seed.sql # Database setup SQL |
| 86 | +├── sync-rules.yaml # PowerSync sync rules |
| 87 | +└── nuxt.config.ts # Nuxt configuration |
| 88 | +``` |
| 89 | + |
| 90 | +## Learn More |
| 91 | + |
| 92 | +- [PowerSync Documentation](https://docs.powersync.com/) |
| 93 | +- [Supabase Documentation](https://supabase.com/docs) |
| 94 | +- [Nuxt Documentation](https://nuxt.com/) |
| 95 | + |
0 commit comments