Skip to content

callmedeci/supabase-webpush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Supabase Edge Function – Push Notifications with Deno

This project demonstrates how to send Web Push Notifications using a Supabase Edge Function and @negrel/webpush.
Since popular web-push libraries don’t work in Deno, this setup converts VAPID keys into JWK format and uses them inside a Supabase Edge Function.

πŸš€ Features

  • Supabase Edge Function with Deno runtime
  • Push Notifications via @negrel/webpush
  • VAPID key conversion utilities
  • Handles multiple subscriptions stored in Supabase
  • CORS enabled (ready for frontend clients)

πŸ“¦ Requirements

  • Supabase project
  • Deno runtime (used by Supabase Edge Functions)
  • A subscriptions table in Supabase

πŸ”‘ VAPID Keys

Generate VAPID keys here β†’ https://vapidkeys.com/

Example output:

{
  "subject": "mailto:test@gmail.com",
  "publicKey": "BNWYBVKIbOTOvSZ-Sk5WYjAtEmPyhyq6axC4aMKg0IFHiPwWSrqDlx7j1sLnOkvdRmVGXiETpbePq_f2b6nDIDw",
  "privateKey": "G3xcRcnvaJvOU6-p49nK0D4ZDCv5O1kD4WF2NGjeS_E"
}

πŸ—„οΈ Subscriptions Table

Create a table in Supabase to store push subscriptions:

create table subscriptions (
  id uuid primary key default gen_random_uuid(),
  created_at timestamp with time zone default now(),
  endpoint text not null,
  keys jsonb not null
);

Example stored data:

{
  "id": "4e4a4567-583b-4229-9c7c-32236d2259a5",
  "created_at": "2025-08-18T07:03:38.709698+00",
  "endpoint": "https://fcm.googleapis.com/fcm/send/cUrTRhWK4Io:APA91bHHV3ljE_0nIe6xi7eyuPitRdAqaLyUQr_ok0mzuJbE5eYLO2p8mt70MCwXuMOnazIsYdVOvZobnuNrhWf9uKhs-iiBSyywHgwwQ9M0xFKGuw2mlnpkx2FeJz5R-pr-aw9q5ith",
  "keys": {
    "auth": "IkRYX7oHtMTTC1bPyb0lBw==",
    "p256dh": "BMVa1/ONWNvzwqczIVJz3q+bkT0yzIOLrgwZfzOd6B3nLi3FgqRSXdpe+kG2Ad4GoGy6MYx6z7H+gJbVB0PKEA8="
  }
}

πŸ“ Credits

About

How I handle creating a new web push in supabase edge function

Topics

Resources

Stars

Watchers

Forks