Blogs
Feb 11, 2025
Send custom Email, SMS, In-App and other types of notifications from Supabase with one library. Including code example using TypeScript and Supabase Edge Functions.
Motivation
Supabase only supports a handful of authentication-related emails internally, which are often inadequate for production applications. This guide will show you how to build a robust notification system on top of Supabase that can:
Send Custom Notifications, e.g. User engagement notifications, system alerts, collaboration notifications.
Send Across Multiple Channels, e.g. Emails, SMS, In-App.
You can find the complete code for this guide in our GitHub repository.
Let's Get Started
Instead of hacking together multiple services and libraries, we will be leveraging:
NotificationAPI which handles the integration and delivery of notifications across different channels.
Supabase Edge Functions to securely integrate with NotificationAPI.
Backend Implementation
First, install NotificationAPI's server SDK:
Now, let's create a sample Supabase Edge Function to send a welcome notification:
Here's the sample code for this function. The code receives an email and optionally a phone number of a recipient, then commands the NotificationAPI library to send the welcome notification to the recipient.
NotificationAPI Configuration
Create a NotificationAPI account.
Create a notification called "welcome" and toggle on the channels you wish (Email, SMS, …)
Optional: Design the template using the visual editor.
Test and Deploy
Set up your NotificationAPI client ID and Secret in environment variables in
supabase/functions/send-welcome-notification/.env
:
You can get these values from NotificationAPI's dashboard. Keep these values secure. This client ID and secret can be used to read and send notifications.
Start Supabase and run the function locally:
Test the function using cURL or the Supabase client:
Or test using the Supabase client in your application:
If you are planning to send SMS, also pass the phoneNumber
parameter to your edge function with a + sign followed by 10 digits, e.g. +15005005555
.
Once you've verified the function works locally, you can deploy it:
Customize the Templates
In order to change how your notifications look like, you can edit them from the NotificationAPI dashboard without coding.
In our code example, we passed the firstName
parameter to your notification. You can display this parameter in a template by placing a {{firstName}}
anywhere in the template designs.
Optional: Front-end Steps for In-app Notifications
For in-app notifications (popups, notification center, badges, etc.), NotificationAPI provides a complete React SDK with pre-built components. Instead of building these features from scratch, you can use their ready-made solutions: NotificationAPI React SDK documentation.
Conclusion
In this guide, we've shown how to build a robust notification system by combining Supabase's serverless infrastructure with NotificationAPI's comprehensive notification features. Instead of spending weeks building custom notification functionality, you can implement a production-ready solution in minutes.
You can find the complete code for this guide in our GitHub repository.
Feel free to fork the repository, submit issues, or contribute improvements. For more examples and use cases, check out our documentation.