Section 4 Official Documentation

Integrating with Other Firebase-Supported Platforms

Send and manage push notifications using Firebase FCM v1 for Flutter and other platforms.

Integrating with Other Firebase-Supported Platforms

Because HosteDay's notification system is built on the standard Firebase Cloud Messaging (FCM v1) protocol, you can connect any Firebase-supported platform (Web JavaScript, native Android, native iOS, or React Native) to your HosteDay App.


Standard Integration Flow for Any Platform

Regardless of your frontend language or framework, the integration follows three standard steps:

  1. Obtain the FCM Device Token: Use the official Firebase SDK for your platform to request notification permission and retrieve the device token.
  2. Register the Token with HosteDay: Send the token to POST /api/notifications/devices/register along with device_id and device_type.
  3. Receive & Handle Notifications: Handle incoming foreground/background notifications and read custom data payloads (such as deep links).

1. Web Applications (JavaScript / Web)

  1. Add firebase-messaging-sw.js to your public/ directory to handle background notifications.
  2. After initializing Firebase Messaging in the browser, retrieve the token and register it with HosteDay:
import { getMessaging, getToken } from 'firebase/messaging';

const messaging = getMessaging(firebaseApp);
const fcmToken = await getToken(messaging, { vapidKey: 'YOUR_VAPID_KEY' });

await fetch('https://my-app.hosteday.com/api/notifications/devices/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-Api-Token': 'YOUR_API_TOKEN',
    'Authorization': `Bearer ${userToken}`,
  },
  body: JSON.stringify({
    device_token: fcmToken,
    device_id: browserDeviceId,
    device_type: 'web',
    device_name: navigator.userAgent,
  }),
});

2. Native Android Apps (Kotlin / Java)

After adding google-services.json and firebase-messaging:

FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
    if (!task.isSuccessful) return@addOnCompleteListener
    val fcmToken = task.result
    // Send fcmToken to POST /api/notifications/devices/register
    // with device_type = "android"
}

3. Native iOS Apps (Swift)

After adding GoogleService-Info.plist and enabling Push Notifications in Xcode:

Messaging.messaging().token { token, error in
    guard let fcmToken = token, error == nil else { return }
    // Send fcmToken to POST /api/notifications/devices/register
    // with device_type = "ios"
}

4. React Native Apps

Using @react-native-firebase/messaging:

import messaging from '@react-native-firebase/messaging';
import { Platform } from 'react-native';

const fcmToken = await messaging().getToken();
// Send fcmToken to POST /api/notifications/devices/register
// with device_type: Platform.OS === 'ios' ? 'ios' : 'android'

Important Notes for All Platforms

  • Token Refresh (onTokenRefresh): Google periodically refreshes device tokens; always listen for token refresh events and re-send the updated token to /api/notifications/devices/register using the same device_id.
  • Unlink on Logout: Call POST /api/notifications/devices/unregister when a user logs out so another user on the same device does not receive personal notifications.
  • Allowed device_type Values: android, ios, web, macos, windows, linux.