A minimal implementation of web push notifications using SvelteKit, PWA, and Supabase. This project demonstrates how to create and manage web push notifications with a serverless backend.
For simplicity, this demo uses a basic in-memory session management system instead of Supabase Auth. In a production application, you would want to implement proper authentication using Supabase Auth or another authentication system. The current implementation uses a default "demo-user" to demonstrate push notification functionality without the complexity of a full authentication system.
git clone https://github.com/thingenineer/sveltekit-supabase-push-notifications.git
cd sveltekit-supabase-push-notifications
npm install # or pnpm install
npx web-push generate-vapid-keys
Save the generated keys for the next step.
Copy the .env.example
file to .env
:
cp .env.example .env
Fill in your Supabase URL, keys, and the VAPID keys from the previous step.
Run the migrations in the Supabase Dashboard SQL editor or using Supabase CLI:
supabase start # If running locally
supabase db push # To push migrations
supabase functions deploy send-notification --project-ref your-project-ref
Make sure to set your VAPID keys as secrets in the Supabase dashboard:
supabase secrets set VAPID_PUBLIC_KEY=your_public_key VAPID_PRIVATE_KEY=your_private_key --project-ref your-project-ref
npm run dev # or pnpm dev
The application will be available at http://localhost:5173.
Database Tables:
users
: Stores user informationuser_devices
: Stores push subscription informationnotif_channels
: Stores notification channelsnotif_channel_users
: Maps users to notification channelsnotif_log
: Logs notification delivery attemptsEdge Function:
send-notification
: Handles notification delivery using web-push