Skip to main content

FCM Push Notifications - Quick Start Guide

What Was Done

We’ve implemented Firebase Cloud Messaging (FCM) to enable native push notifications for your mobile app. This works alongside your existing in-app notification system.

Files Created/Modified

New Files

  1. Type Definitions
    • Updated types/models/users.ts - Added FCMToken type and fcmTokens field to user model
  2. API Endpoints
    • pages/api/notifications/register-fcm-token.ts - Register device tokens
    • pages/api/notifications/remove-fcm-token.ts - Remove device tokens
    • pages/api/notifications/update-fcm-token-usage.ts - Update token usage
  3. Backend Utilities
    • firebase/server/fcm/buildNotificationPayload.ts - Converts notifications to FCM format
    • firebase/server/fcm/sendPushNotification.ts - Sends FCM push notifications
    • firebase/server/fcm/index.ts - FCM utilities export
  4. Frontend Hooks
    • hooks/notifications/useFCMTokenRegistration.ts - React hooks for token management
  5. Documentation
    • docs/engineering/notifications/fcm-push-notifications.mdx - Complete implementation guide
    • docs/engineering/notifications/fcm-quick-start.md - This file

Modified Files

  • firebase/server/notifications.ts - Extended to send FCM push notifications

How It Works

Next Steps for Mobile App

1. Install Dependencies (React Native/Expo)

2. Request Permissions & Get Token

3. Register Token with Backend

4. Handle Notification Taps

5. Configure Notification Behavior

Testing

1. Test Token Registration

2. Trigger a Test Notification

  • Create a test booking in your app
  • The notification should automatically be sent
  • Check device for push notification

3. Test from Firebase Console

  1. Go to Firebase Console → Cloud Messaging
  2. Click “Send test message”
  3. Enter your device’s FCM token
  4. Send notification

Platform-Specific Setup

iOS

  1. Enable Push Notifications in Xcode
    • Open iOS project in Xcode
    • Select target → Signing & Capabilities
    • Add “Push Notifications” capability
  2. Configure APNs
    • Create APNs key in Apple Developer Console
    • Upload to Firebase Console (Project Settings → Cloud Messaging → iOS)
  3. Update Info.plist (if needed)

Android

  1. Add google-services.json
    • Download from Firebase Console
    • Place in android/app/ directory
  2. Update AndroidManifest.xml (usually automatic with Expo)

Backend - Already Done! ✅

The backend automatically:
  • Sends FCM notifications when createNotification() is called
  • Cleans up invalid/expired tokens
  • Handles multiple devices per user
  • Logs delivery results
No additional backend work needed!

Troubleshooting

”No FCM tokens found for user”

  • User hasn’t registered their device yet
  • Check that token registration is called after login

”Permission not granted”

  • User denied notification permissions
  • Re-request permissions or guide user to settings

Notifications not appearing

  • Verify token is registered (check Firestore user document)
  • Check Firebase Console logs for errors
  • Ensure physical device (not simulator for iOS)
  • For iOS: Verify APNs certificate is configured

Token registration fails

  • Check network connectivity
  • Verify user is authenticated
  • Check API endpoint is accessible

Monitoring

Check these for notification delivery:
  1. Firebase Console
    • Cloud Functions → Logs
    • Look for “FCM notification sent” messages
  2. User Documents in Firestore
    • Navigate to users/{userId}
    • Check fcmTokens field
    • Verify tokens are present
  3. Backend Logs
    • Watch for “Failed to send push notification” errors
    • Check token cleanup messages

Support

  • Full documentation: docs/engineering/notifications/fcm-push-notifications.mdx
  • Current in-app system: docs/engineering/notifications/notifications-structure.mdx
  • Email notifications: docs/engineering/notifications/email-notifications.mdx

Summary

Backend: Complete - FCM automatically sends when notifications are created ✅ API Endpoints: Complete - Token registration/removal endpoints ready ✅ Frontend Hooks: Complete - React hooks ready for mobile app ⏳ Mobile Integration: Next step - Add to React Native/Expo app Your notification system now supports:
  • ✅ In-app notifications (existing)
  • ✅ Email notifications (existing)
  • ✅ Native push notifications (NEW!)