Skip to content

Commit e5c95ac

Browse files
author
Amine
committed
feat: add Nuxt Supabase Todo List demo with environment configuration and initial setup
1 parent db1ecce commit e5c95ac

File tree

21 files changed

+4596
-1653
lines changed

21 files changed

+4596
-1653
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22
lib
33
dist
44
.nuxt
5+
.output
56
*.tsbuildinfo
67
.vscode
78
.DS_STORE
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
imports.autoImport=true

demos/nuxt-supabase-todolist/README

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default defineAppConfig({
2+
ui: {
3+
colors: {
4+
primary: 'indigo',
5+
neutral: 'stone',
6+
},
7+
input: {
8+
variants: {
9+
variant: {
10+
subtle: 'ring-default bg-elevated/50',
11+
},
12+
},
13+
},
14+
header: {
15+
slots: {
16+
root: 'border-none',
17+
},
18+
},
19+
},
20+
})
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<UApp>
3+
<NuxtLayout>
4+
<NuxtPage />
5+
</NuxtLayout>
6+
</UApp>
7+
</template>
8+
9+
<script setup lang="ts">
10+
useHead({
11+
meta: [{ name: 'viewport', content: 'width=device-width, initial-scale=1' }],
12+
link: [{ rel: 'icon', href: '/favicon.ico' }],
13+
htmlAttrs: {
14+
lang: 'en',
15+
},
16+
})
17+
18+
const title = 'PowerSync Playground'
19+
const description
20+
= 'Demo of a simple todo list app using PowerSync and Supabase.'
21+
22+
useSeoMeta({
23+
title,
24+
ogTitle: title,
25+
description,
26+
ogDescription: description,
27+
})
28+
29+
const appIsReady = ref(false)
30+
31+
provide('appIsReady', readonly(appIsReady))
32+
33+
const powerSync = usePowerSync()
34+
const syncStatus = usePowerSyncStatus()
35+
36+
const user = useSupabaseUser()
37+
const { logger: powerSyncLogger } = useDiagnosticsLogger()
38+
39+
watch(user, () => {
40+
if (user) {
41+
if (syncStatus.value.hasSynced) {
42+
powerSyncLogger.log('User is logged in and has synced...', { user: user, syncStatus: syncStatus.value })
43+
appIsReady.value = true
44+
}
45+
else {
46+
powerSyncLogger.log('User is logged waiting for first sync...', { user: user, syncStatus: syncStatus.value })
47+
powerSync.value.waitForFirstSync().then(() => {
48+
appIsReady.value = true
49+
})
50+
}
51+
}
52+
else {
53+
powerSyncLogger.log('User is not logged in disconnecting...', { user: user, syncStatus: syncStatus.value })
54+
powerSync.value.disconnect()
55+
appIsReady.value = true
56+
}
57+
}, { immediate: true })
58+
</script>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import "tailwindcss";
2+
@import "@nuxt/ui";
3+
4+
:root {
5+
--ui-header-height: 40px;
6+
7+
--ui-container: 100%;
8+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<script setup lang="ts">
2+
const client = useSupabaseClient()
3+
const user = useSupabaseUser()
4+
const powerSync = usePowerSync()
5+
6+
const logout = async () => {
7+
await powerSync.value.disconnectAndClear()
8+
9+
await client.auth.signOut()
10+
navigateTo('/login')
11+
}
12+
</script>
13+
14+
<template>
15+
<UHeader :toggle="false">
16+
<template #left>
17+
<UButton
18+
variant="link"
19+
@click="navigateTo('/')"
20+
>
21+
<img
22+
src="https://cdn.prod.website-files.com/67eea61902e19994e7054ea0/67f910109a12edc930f8ffb6_powersync-icon.svg"
23+
alt="Powersync"
24+
class="size-10 inline-flex"
25+
>
26+
</UButton>
27+
</template>
28+
29+
<template #right>
30+
<UColorModeButton variant="link" />
31+
32+
<UButton
33+
v-if="user"
34+
variant="link"
35+
class="cursor-pointer"
36+
color="neutral"
37+
@click="logout"
38+
>
39+
Logout
40+
</UButton>
41+
</template>
42+
</UHeader>
43+
</template>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- Past this into your Superbase SQL Editor
2+
3+
-- Note: change this if changing the DB connection name
4+
-- connect postgres;
5+
-- 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+
);
13+
14+
CREATE TABLE public.todos(
15+
id uuid NOT NULL DEFAULT gen_random_uuid(),
16+
created_at timestamp with time zone NOT NULL DEFAULT now(),
17+
completed_at timestamp with time zone NULL,
18+
description text NOT NULL,
19+
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)
25+
);
26+
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());
36+
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);
45+
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);
54+
55+
-- Create publication for PowerSync tables
56+
CREATE PUBLICATION powersync FOR ALL TABLES;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-check
2+
import withNuxt from './.nuxt/eslint.config.mjs'
3+
4+
export default withNuxt({
5+
rules: {
6+
'@typescript-eslint/no-explicit-any': 'off',
7+
'nuxt/nuxt-config-keys-order': 'off',
8+
},
9+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<div>
3+
<AppHeader />
4+
5+
<UMain>
6+
<slot />
7+
</UMain>
8+
</div>
9+
</template>

0 commit comments

Comments
 (0)