Skip to content

Latest commit

 

History

History
92 lines (65 loc) · 3.24 KB

File metadata and controls

92 lines (65 loc) · 3.24 KB

PetFolio — Firebase FCM (petfolio-v1)

Project: petfolio-v1 · Sender ID: 86798095066

Firebase CLI (logged-in)

firebase projects:list
firebase use petfolio-v1
firebase apps:list --project petfolio-v1

Refresh Flutter + Android + web config from the console (no MCP required):

.\tool\sync_firebase_from_cli.ps1

Or manually:

flutterfire configure --project=petfolio-v1 --yes --platforms=android,web --out=lib/firebase_options.dart
firebase apps:sdkconfig ANDROID --project petfolio-v1 -o android/app/google-services.json

Web service worker config: web/firebase-config.js (generated by the script above from firebase apps:sdkconfig WEB).

Repo files: .firebaserc, firebase.json, lib/firebase_options.dart, android/app/google-services.json.

Client

  1. .env must include FIREBASE_VAPID_KEY (Firebase Console → Cloud Messaging → Web Push certificates → Key pair public value; CLI does not expose this).
  2. Run: flutter run --dart-define-from-file=.env
  3. Sign in so FCM tokens register in user_fcm_devices.

Server push (Supabase)

Set secrets via CLI (from repo root). The JSON must be a single minified line (invalid JSON in the secret causes send-fcm-notification HTTP 500):

# Place petfolio-v1-firebase-adminsdk-*.json in repo root (gitignored), then:
.\tool\set_fcm_supabase_secrets.ps1
# Or: .\tool\set_fcm_supabase_secrets.ps1 -ServiceAccountPath "C:\path\to\key.json"

Or manually:

# One-time: minify service account JSON + random dispatch UUID into a temp env file, then:
npx supabase secrets set --env-file supabase/.secrets.fcm.env --project-ref jqyjvhwlcqcsuwcqgcwf

Required secrets: FIREBASE_SERVICE_ACCOUNT_JSON, FCM_DISPATCH_SECRET (must match SQL below).

SQL (same UUID as FCM_DISPATCH_SECRET in Supabase):

UPDATE private.fcm_internal_config
SET dispatch_secret = 'your-uuid-here'
WHERE id = 1;

Status: Secrets pushed via CLI; private.fcm_internal_config.dispatch_secret synced on hosted project.

npx supabase functions deploy send-fcm-notification --no-verify-jwt
npx supabase functions deploy process-fcm-outbox --no-verify-jwt
npx supabase functions deploy process-care-fcm-reminders --no-verify-jwt

Automatic FCM events

Event Source
Like, comment, follow, KYC notifications INSERT
Chat message chat_messages INSERT
New match matches INSERT
Order status marketplace_orders UPDATE
Care reminders care_web_reminders + cron

Chat notification sound

  • Android: android/app/src/main/res/raw/chat_message.wav + channel petfolio_chat_v2 (created at app start; legacy petfolio_chat is removed on launch).
  • iOS: ios/Runner/chat_message.wav in the app bundle.
  • Server: Chat Android pushes are data-only (tray + sound via flutter_local_notifications); iOS uses APNs alert + chat_message.wav.
  • Replace chat_message.wav with your own short sound (keep the filename) and reinstall the app so Android recreates the channel.

Test

  1. Run app, sign in, allow notifications.
  2. Firebase Console → Messaging → test message with device FCM token from debug logs.
  3. Or trigger in-app (e.g. send a chat message to another user with FCM registered).