translation

This is an AI translated post.

Kofsitho

Building a Real-time Push Notification System using Supabase and FCM

Select Language

  • English
  • 汉语
  • Español
  • Bahasa Indonesia
  • Português
  • Русский
  • 日本語
  • 한국어
  • Deutsch
  • Français
  • Italiano
  • Türkçe
  • Tiếng Việt
  • ไทย
  • Polski
  • Nederlands
  • हिन्दी
  • Magyar

Summarized by durumis AI

  • This article explores how to build a real-time push notification system leveraging Deno, Supabase, and Firebase Cloud Messaging (FCM).
  • By utilizing Supabase's real-time database features and FCM, you can construct a system that delivers instant information to users, enhancing interaction and engagement.
  • This guide provides step-by-step instructions with practical code examples, covering Deno and Supabase client setup, database change detection, and push notification delivery via FCM.
Building a real-time push notification system using Deno, Supabase, and Firebase Cloud Messaging

Building a real-time push notification system using Deno, Supabase, and Firebase Cloud Messaging

Introduction

  • Importance of Real-time Push Notifications
  • Introducing Deno, Supabase, and Firebase Cloud Messaging (FCM)

Server Setup with Deno and Supabase

  • Introduction to Deno and its features
  • Setting up Supabase client
  • Secure configuration management through environment variables

Real-time Database Change Detection

  • Introducing the real-time capabilities of Supabase
  • Defining interfaces for detecting database changes

Sending Push Notifications using Firebase Cloud Messaging

  • Role and importance of FCM
  • Obtaining access token using Google service account
  • Push notification sending logic from Deno server using FCM

Conclusion

  • Advantages of using Deno, Supabase, and FCM
  • Contributions of the real-time push notification system to user experience

1. Introduction

Real-time push notifications are a key factor in maximizing user experience in today's digital age. This article explores how to build a real-time push notification system using Deno, Supabase, and Firebase Cloud Messaging (FCM). This article is intended for developers interested in Deno and cloud services.


2. Server Setup with Deno and Supabase

Deno is a modern JavaScript and TypeScript runtime created to overcome the limitations of Node.js. Supabase is an open-source backend service based on PostgreSQL, providing real-time database capabilities. By combining these two technologies, we can build a powerful and flexible backend system.


Code Example: Setting up Supabase client


import { createClient } from 'npm:@supabase/supabase-js@2'
const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!

This code shows how to initialize the Supabase client. Here, we use Deno's environment variable functionality to securely manage Supabase connection information.


3. Real-time Database Change Detection

Supabase's Web Hook feature allows you to immediately detect and respond to changes in the database. This allows you to quickly deliver the latest information to users.


Code Example: Defining webhook payload


interface Post {
id: string
title: string
content: string
}
interface WebhookPayload {
type: 'INSERT'
table: string
record: Post
schema: 'public'
}
// When a new post is added to the posts table, send a push notification to all users
Deno.serve(async (req) => {
// Extract the webhook payload from the request.
const payload: WebhookPayload = await req.json()
console.log("payload: ", payload);

These interfaces are defined to handle data change events that occur in Supabase. The Post interface defines the structure of post data, and the WebhookPayload defines the structure of the data received from the webhook.


4. Sending Push Notifications using Firebase Cloud Messaging

FCM is a powerful service that can send push notifications across multiple platforms. By sending notifications through FCM from the Deno server, users can receive new posts or important updates immediately.


Code Example: Sending push notifications through FCM


import serviceAccount from '../serviceAccountKey.json' with { type: 'json' }
// Function to obtain access token from Google service account
const getAccessToken = ({
clientEmail,
privateKey,
}: {
clientEmail: string
privateKey: string
}): Promise => {

This code shows the process of the Deno server sending push notifications using FCM. Here, we use a Google service account to obtain the access token required for FCM.


5. Conclusion

Building a real-time push notification system using Deno, Supabase, and FCM is very useful in modern web development. This system allows developers to provide immediate information delivery and enhanced interaction to users. Through the technologies and code examples introduced in this article, developers can gain the knowledge and tools necessary to build their own real-time notification system.


kofsitho
Kofsitho
Kofsitho
kofsitho
How to Subscribe to durumis RSS Learn how to use RSS feeds to receive blog post update notifications. We help you conveniently set up notifications through various tools such as Slack and Feedly so you don't miss any new posts.
durumis official blog
durumis official blog
RSS icon
durumis official blog
durumis official blog

May 8, 2024

[Non-Major, Surviving as a Developer] 12. English for New Developers New developers are advised to prioritize learning IT-related terminology and syntax for improving their English skills. Understanding terms commonly used in the field, such as back-end, front-end, API, SDK, etc., can help them adapt quickly to development
투잡뛰는 개발 노동자
투잡뛰는 개발 노동자
투잡뛰는 개발 노동자
투잡뛰는 개발 노동자
투잡뛰는 개발 노동자

April 1, 2024

Email Sending Service Price Comparison We have compared and analyzed various email services such as Naver, NHN, AWS, and SendGrid. As a result of examining the free upper limit and the cost per unit, AWS SES is the cheapest at 0.1 won per unit. Currently, we are using NCP Outbound Mailer, but
해리슨 블로그
해리슨 블로그
해리슨 블로그
해리슨 블로그
해리슨 블로그

March 10, 2024

Blog About Web Development, SEO, and the Role of Developers Here is a snippet I wrote based on my understanding of the blog content: The Devapenseo Webian blog discusses web development, SEO, and the role of developers in building effective and search engine optimized websites. The author of the blog
Devapenseo Webian
Devapenseo Webian
devapenseo webian
Devapenseo Webian
Devapenseo Webian

February 23, 2024

🚀 Earn money daily with SNS app tech, Warpcast airdrop! Ethereum founder Vitalik Buterin [Bitcoin/NFT] Warpcast, a social app supported by Ethereum founder Vitalik Buterin, is based on Farcaster and similar to Twitter, allowing you to farm Degen through participation. The active badge activation criteria are strict, but it is considered a high-potential pr
팀 세력, SEPOWER
팀 세력, SEPOWER
팀 세력, SEPOWER
팀 세력, SEPOWER
팀 세력, SEPOWER

April 23, 2024

Durumis Development - Part 2: Infrastructure Durumis uses GCP for global service, and provides services in 7 regions worldwide, including Seoul, Singapore, Mumbai, Belgium, South Carolina, Sao Paulo, and Los Angeles. Users can view articles and images quickly from the nearest region. The technologie
해리슨 블로그
해리슨 블로그
GCP Location
해리슨 블로그
해리슨 블로그

January 25, 2024