UXDL Docs

Firebase Cloud Messaging

Firebase project setup for web, iOS, and Android push.

FCM delivers push notifications to web browsers, iOS, and Android. The backend sends messages via a Firebase service account — one token registry for all platforms.

Firebase project setup

  1. Create a project in the Firebase Console
  2. Register apps for each platform:
    • Web — add a web app, copy the Firebase config object
    • iOS — add iOS app with correct bundle ID
    • Android — add Android app with correct package name
  3. Download google-services.json (Android) and GoogleService-Info.plist (iOS) for mobile teams

Web — VAPID key

Required for browser push notifications:

  1. Firebase Console → Project Settings → Cloud Messaging
  2. Under Web configuration, generate a Web Push certificate (VAPID key pair)
  3. Expose the public key to the frontend as NEXT_PUBLIC_FCM_VAPID_KEY

Browsers require HTTPS (except localhost) and a registered service worker before granting push permission.

Service account (backend)

  1. Firebase Console → Project Settings → Service Accounts
  2. Generate new private key → store JSON in AWS Secrets Manager
  3. Map to env vars: FCM_PROJECT_ID, FCM_CLIENT_EMAIL, FCM_PRIVATE_KEY

Frontend environment (web)

dotenv
NEXT_PUBLIC_FIREBASE_API_KEY=...
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=...
NEXT_PUBLIC_FIREBASE_APP_ID=...
NEXT_PUBLIC_FCM_VAPID_KEY=BPxxx...

iOS — APNs configuration

  1. Apple Developer → Certificates, Identifiers & Profiles → Keys
  2. Create APNs Auth Key (.p8)
  3. Upload to Firebase Console → Project Settings → Cloud Messaging → Apple app configuration

Android

No extra backend config — FCM handles delivery when google-services.json is in the app.

Device token lifecycle

EventAction
User logs inClient registers token via POST /v1/devices with platform: web | ios | android
Token refreshClient re-registers (FCM may rotate tokens)
User logs outDelete token from database
User denies web permissionSkip registration — fall back to Socket.io in-app only
registration-token-not-registeredBackend removes stale token on send failure

Platform support

PlatformDelivery whenRequires
WebTab backgrounded or closedHTTPS, service worker, user permission
iOSApp backgrounded or closedAPNs key in Firebase
AndroidApp backgrounded or closedgoogle-services.json in app

Express implementation

See Push — FCM for firebase-admin setup, web client code, and send helpers.

Official documentation