Skip to content

Commit 5771c58

Browse files
author
Amine
committed
feat: add README and update seed.sql for Nuxt Supabase Todo List demo
1 parent c58db3c commit 5771c58

File tree

3 files changed

+106
-39
lines changed

3 files changed

+106
-39
lines changed

demos/nuxt-supabase-todolist/README

Whitespace-only changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,28 @@
11
-- Past this into your Superbase SQL Editor
22

3-
-- Note: change this if changing the DB connection name
3+
-- TODO change this if changing the DB connection name
44
-- connect postgres;
55
-- Create tables
6-
CREATE TABLE public.lists(
7-
id uuid NOT NULL DEFAULT gen_random_uuid(),
8-
created_at timestamp with time zone NOT NULL DEFAULT now(),
9-
name text NOT NULL,
10-
owner_id uuid NOT NULL,
11-
CONSTRAINT lists_pkey PRIMARY KEY (id)
12-
);
136

14-
CREATE TABLE public.todos(
7+
CREATE TABLE IF NOT EXISTS public.tasks(
158
id uuid NOT NULL DEFAULT gen_random_uuid(),
169
created_at timestamp with time zone NOT NULL DEFAULT now(),
1710
completed_at timestamp with time zone NULL,
1811
description text NOT NULL,
1912
completed boolean NOT NULL DEFAULT FALSE,
20-
created_by uuid NULL,
21-
completed_by uuid NULL,
22-
list_id uuid NOT NULL,
23-
photo_id uuid NULL,
24-
CONSTRAINT todos_pkey PRIMARY KEY (id)
13+
user_id uuid NOT NULL,
14+
CONSTRAINT tasks_pkey PRIMARY KEY (id)
2515
);
2616

27-
-- Creates some initial data to be synced
28-
INSERT INTO lists(
29-
id,
30-
name,
31-
owner_id)
32-
VALUES (
33-
'75f89104-d95a-4f16-8309-5363f1bb377a',
34-
'Getting Started',
35-
gen_random_uuid());
17+
-- Create a role/user with replication privileges for PowerSync
18+
CREATE ROLE powersync_role WITH REPLICATION BYPASSRLS LOGIN PASSWORD 'postgres_12345';
19+
-- Set up permissions for the newly created role
20+
-- Read-only (SELECT) access is required
21+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO powersync_role;
3622

37-
INSERT INTO todos(
38-
description,
39-
list_id,
40-
completed)
41-
VALUES (
42-
'Run services locally',
43-
'75f89104-d95a-4f16-8309-5363f1bb377a',
44-
TRUE);
23+
-- Optionally, grant SELECT on all future tables (to cater for schema additions)
24+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO powersync_role;
4525

46-
INSERT INTO todos(
47-
description,
48-
list_id,
49-
completed)
50-
VALUES (
51-
'Create a todo here. Query the todos table via a Postgres connection. Your todo should be synced',
52-
'75f89104-d95a-4f16-8309-5363f1bb377a',
53-
FALSE);
5426

5527
-- Create publication for PowerSync tables
5628
CREATE PUBLICATION powersync FOR ALL TABLES;

0 commit comments

Comments
 (0)