Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com> configuracion inicial para supoabase y endpoints
2.8 KiB
2.8 KiB
Firebase setup for Recolecta project
This document explains the manual steps to create a Firebase project, register Android/iOS apps, obtain the Admin SDK credentials for backend (FCM), and connect the Flutter app.
-
Create a Firebase project
- Go to https://console.firebase.google.com/ and create a new project (e.g.,
recolecta-demo).
- Go to https://console.firebase.google.com/ and create a new project (e.g.,
-
Register Android app
- In the Firebase console, add an Android app. Use the app package name that matches your Flutter app (check
android/app/src/main/AndroidManifest.xmlorandroid/app/build.gradleapplicationId). - Download
google-services.jsonand place it in the Flutter project atrecolecta_app/android/app/google-services.json. - Update
android/build.gradleandandroid/app/build.gradleif needed (standard Flutter - Firebase steps). See https://firebase.flutter.dev/docs/overview/#installation
- In the Firebase console, add an Android app. Use the app package name that matches your Flutter app (check
-
Register iOS app
- Add an iOS app in Firebase, set the iOS bundle id from your Flutter project (check
ios/Runner.xcodeproj), downloadGoogleService-Info.plistand add it torecolecta_app/ios/Runner/GoogleService-Info.plist(open Xcode and add to Runner target).
- Add an iOS app in Firebase, set the iOS bundle id from your Flutter project (check
-
Enable Cloud Messaging
- In Firebase console go to Cloud Messaging and ensure that your app is configured.
-
Obtain Admin SDK credentials (Backend)
- In Firebase Console: Project Settings → Service Accounts → Generate new private key.
- This downloads a JSON file like
recolecta-adminsdk-xxxxx.json. - Copy that file to the backend secrets folder:
backend/secrets/firebase-adminsdk.json(createbackend/secrets/if missing). - IMPORTANT: do NOT commit this file to git.
backend/.gitignorealready excludessecrets/.
-
Set environment variable for backend
- Set
FIREBASE_CREDENTIALS_PATHto the path where you placed the JSON, example in.env:
- Set
FIREBASE_CREDENTIALS_PATH=backend/secrets/firebase-adminsdk.json
- Flutter configuration (pubspec)
- Add
firebase_coreandfirebase_messagingtorecolecta_app/pubspec.yamland runflutter pub get. - Initialize Firebase in Flutter
main()per docs:WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); - Subscribe the citizen client to the route topic after confirming their
routeId:
- Add
FirebaseMessaging.instance.subscribeToTopic('topic_RUTA-01');
-
Testing push (backend)
- The backend contains
app/services/notifications.pywhich will use the Admin SDK ifFIREBASE_CREDENTIALS_PATHis set and the file exists. Otherwise it falls back to a mock that prints messages. - Start backend and trigger
POST /simulate/tickto see mock pushes or real pushes if Admin SDK is configured.
- The backend contains
-
Security note
- Keep the Admin SDK JSON secret. Use environment-managed secrets in production (Cloud Run secret manager, etc.).