Firebase Setup & Configuration
Firebase initialization, authentication, and core configuration
Firebase Setup
BabyShopHub relies on Firebase for real-time database, authentication, and push notifications. This document covers the initialization process and core setup.
Initialization
The app initializes Firebase before runApp() is called in main.dart. We use firebase_options.dart generated by the FlutterFire CLI.
Authentication Configuration
We use firebase_auth for all identity management.
- Email & Password: Native email/password auth is enabled.
- Google Sign-In: Configured using the
google_sign_inpackage. Requires SHA-1 and SHA-256 fingerprints in the Firebase Console. - Apple Sign-In: Configured for iOS users via
sign_in_with_apple.
Firebase Options (firebase_options.dart)
This file contains the API keys, App IDs, and Sender IDs for Web, Android, and iOS. Never manually edit this file. If you add a new Firebase service, regenerate it:
Platform-Specific Setup
- Android: The
google-services.jsonmust be placed inandroid/app/. Thebuild.gradleis pre-configured with the Google Services plugin. - iOS: The
GoogleService-Info.plistis linked via Xcode. Ensure you openios/Runner.xcworkspaceto manage it, not the.xcodeproj. - Web: Web keys are injected directly via
firebase_options.dart.
Best Practices
- Always catch
FirebaseAuthExceptionto display localized, user-friendly error messages. - Use
userChanges()orauthStateChanges()streams inAuthProviderrather than manually checkingcurrentUser.