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
-
Type Definitions
- Updated
types/models/users.ts- AddedFCMTokentype andfcmTokensfield to user model
- Updated
-
API Endpoints
pages/api/notifications/register-fcm-token.ts- Register device tokenspages/api/notifications/remove-fcm-token.ts- Remove device tokenspages/api/notifications/update-fcm-token-usage.ts- Update token usage
-
Backend Utilities
firebase/server/fcm/buildNotificationPayload.ts- Converts notifications to FCM formatfirebase/server/fcm/sendPushNotification.ts- Sends FCM push notificationsfirebase/server/fcm/index.ts- FCM utilities export
-
Frontend Hooks
hooks/notifications/useFCMTokenRegistration.ts- React hooks for token management
-
Documentation
docs/engineering/notifications/fcm-push-notifications.mdx- Complete implementation guidedocs/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
- Go to Firebase Console → Cloud Messaging
- Click “Send test message”
- Enter your device’s FCM token
- Send notification
Platform-Specific Setup
iOS
-
Enable Push Notifications in Xcode
- Open iOS project in Xcode
- Select target → Signing & Capabilities
- Add “Push Notifications” capability
-
Configure APNs
- Create APNs key in Apple Developer Console
- Upload to Firebase Console (Project Settings → Cloud Messaging → iOS)
-
Update Info.plist (if needed)
Android
-
Add google-services.json
- Download from Firebase Console
- Place in
android/app/directory
-
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
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:-
Firebase Console
- Cloud Functions → Logs
- Look for “FCM notification sent” messages
-
User Documents in Firestore
- Navigate to
users/{userId} - Check
fcmTokensfield - Verify tokens are present
- Navigate to
-
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!)