# Mobile push notification setup

The app's push pipeline (`lib/features/push/`) is wired but inert until the
Firebase client configuration exists for the Flutter app. The backend is now on
Firebase Admin SDK / FCM HTTP v1 and does not use the deprecated legacy server
key for sends.

## Server credential

For local development, the service-account key lives outside git at:

```text
backend/secrets/firebase-admin.json
```

The backend reads it through `GOOGLE_APPLICATION_CREDENTIALS` or
`FIREBASE_CREDENTIALS_PATH`. Docker mounts `backend/secrets` into `/app/secrets`
and defaults both variables to `/app/secrets/firebase-admin.json`.

The admin portal at `/settings/notifications` can also store a Firebase service
account JSON encrypted in the database. Leave that field blank if the server
file should remain the active credential.

## Flutter client setup

Run from `mobile/` when you have Firebase project access:

```bash
dart pub global activate flutterfire_cli
flutterfire configure \
  --project=sehat-a4c23 \
  --platforms=ios,android \
  --out=lib/firebase_options.dart
```

That command creates `lib/firebase_options.dart` and writes native config files
such as `android/app/google-services.json` and `ios/Runner/GoogleService-Info.plist`.
The Android Gradle Google services plugin is declared and only applied when
`android/app/google-services.json` exists, so local builds do not fail before the
client config has been downloaded.

## Smoke testing

1. Enable push in the admin portal notification settings.
2. Sign in on a real device or a Google Play-enabled Android emulator.
3. Confirm a row appears in `device_tokens`.
4. Trigger a notification flow, for example booking or assigning an appointment.
5. Confirm the push arrives and tapping it opens the intended in-app route.

## Code map

- `lib/features/push/data/push_service.dart` - Firebase Messaging registration.
- `lib/features/push/data/push_api.dart` - sends device tokens to the backend.
- `lib/features/push/presentation/providers/push_bridge.dart` - auth lifecycle.
- `core/navigation/app_router.dart` - notification deep-link navigation.
