Skip to Content
API v1IntegrationsFirebase Integration

Firebase Integration

Overview

Firebase is used for two purposes in the API:

  1. Firebase Cloud Messaging (FCM) - Push notifications to mobile devices
  2. Firebase Realtime Database - Real-time chat message storage

Setup

Firebase is initialized in api/include/dbcon.php using the Kreait Firebase Admin SDK:

use Kreait\Firebase\Factory; $factory = (new Factory) ->withServiceAccount(json_decode($_ENV['FIREBASE_CREDENTIALS'], true)) ->withDatabaseUri($_ENV['FIREBASE_DATABASE_URL']); $database = $factory->createDatabase(); $messaging = $factory->createMessaging();

The FIREBASE_CREDENTIALS environment variable contains the full Firebase service account JSON (stored as a string in AWS Secrets Manager).

Firebase Projects by Environment

EnvironmentFirebase Database URL
UK Devhttps://housr-firebase.firebaseio.com
UK UAThttps://housr-firebase-uat.firebaseio.com
UK Prodhttps://housr-firebase-default-rtdb.firebaseio.com
US Demohttps://housr-us-demo.firebaseio.com
US Devhttps://myhousr-dev.firebaseio.com
US UAThttps://myhousr-uat.firebaseio.com
US Prodhttps://myhousr-prod.firebaseio.com

Cloud Messaging (FCM)

Push notifications are sent using the Kreait Messaging service.

Sending Notifications

From api/utils/notificationUtils.php:

function sendNotification(string $title, string $body, array $data = [], array $fcmTokens = []) { global $messaging; foreach ($fcmTokens as $fcmToken) { $message = CloudMessage::withTarget(MessageTarget::TOKEN, $fcmToken) ->withNotification(Notification::create($title, $body)) ->withData($data) ->withHighestPossiblePriority(); $messaging->send($message); } }

FCM Token Management

  • Tokens are stored in the users.fcm_token column
  • Updated via api/updateFCM.php when the app registers/refreshes
  • Set to NULL when the user signs out

Legacy FCM (Direct HTTP)

Some older code (e.g., in signup.php) uses direct HTTP calls to the FCM legacy API (https://fcm.googleapis.com/fcm/send) with a server key, rather than the Kreait SDK. This pattern predates the SDK adoption.

Realtime Database

The Firebase Realtime Database is used for real-time chat messaging. The $database object provides read/write access.

The API manages chat room metadata in MySQL (via chat_rooms and chat_room_members tables), while actual message content and real-time delivery is handled through Firebase Realtime Database. The mobile app reads and writes messages directly to Firebase.

Dependencies

From composer.json:

"kreait/laravel-firebase": "^5.3.0"

Note: Despite the package name including “laravel”, it’s used standalone (not within a Laravel framework). Only the Firebase Factory and service classes are used.

Last updated on