diff --git a/jetpacker/README.md b/jetpacker/README.md index 165abf84..cd023568 100644 --- a/jetpacker/README.md +++ b/jetpacker/README.md @@ -68,8 +68,13 @@ This project is built using the standard Android Gradle build system, allowing d - Update `sdk.dir` inside `local.properties` with your local Android SDK directory path. 2. **Firebase Setup (`google-services.json`)**: - - Register the application in your Firebase Project Console. - - Download the project's custom `google-services.json` and place it in the `android/app/` directory (overwriting the mock placeholder file). + - Register an Android app in your **Firebase Project Console** using the package name `com.example.jetpacker`. + - In the Firebase Console, navigate to **Authentication** -> **Sign-in method** and enable **Anonymous** sign-in (used for session-based communication with the booking coordinator and AI services). + - Download your project's `google-services.json` and place it in the `android/app/` directory (replacing the mock placeholder file). The Gradle `google-services` plugin automatically parses this file and configures the required resources at build time—no code changes or extra XML files are required. + - *Git Safety*: To prevent accidentally committing your personal Firebase credentials back to the repository, tell git to ignore local changes to this file: + ```bash + git update-index --skip-worktree android/app/google-services.json + ``` 3. **Firebase App Check Debug Attestation**: - Run the application on an emulator or a connected device. diff --git a/jetpacker/android/app/src/main/kotlin/com/example/jetpacker/JetPackerApplication.kt b/jetpacker/android/app/src/main/kotlin/com/example/jetpacker/JetPackerApplication.kt index 0108e18d..09ad16f6 100644 --- a/jetpacker/android/app/src/main/kotlin/com/example/jetpacker/JetPackerApplication.kt +++ b/jetpacker/android/app/src/main/kotlin/com/example/jetpacker/JetPackerApplication.kt @@ -36,17 +36,24 @@ class JetPackerApplication : Application() { ComposeUiFlags.isMediaQueryIntegrationEnabled = true super.onCreate() FeatureFlags.initialize(this) - Firebase.initialize(context = this) - Firebase.appCheck.installAppCheckProviderFactory( - DebugAppCheckProviderFactory.getInstance(), - ) - Firebase.auth.signInAnonymously() - .addOnCompleteListener { task -> - if (task.isSuccessful) { - Log.d("JetPackerApplication", "Anonymous auth successful") - } else { - Log.w("JetPackerApplication", "Anonymous auth failed", task.exception) - } + try { + if (Firebase.initialize(context = this) != null) { + Firebase.appCheck.installAppCheckProviderFactory( + DebugAppCheckProviderFactory.getInstance(), + ) + Firebase.auth.signInAnonymously() + .addOnCompleteListener { task -> + if (task.isSuccessful) { + Log.d("JetPackerApplication", "Anonymous auth successful") + } else { + Log.w("JetPackerApplication", "Anonymous auth failed", task.exception) + } + } + } else { + Log.w("JetPackerApplication", "Firebase not initialized") } + } catch (e: Exception) { + Log.w("JetPackerApplication", "Firebase initialization error", e) + } } } diff --git a/jetpacker/android/feature/trip/booking_assistant/src/main/kotlin/com/example/jetpacker/feature/booking_assistant/BookingAssistantViewModel.kt b/jetpacker/android/feature/trip/booking_assistant/src/main/kotlin/com/example/jetpacker/feature/booking_assistant/BookingAssistantViewModel.kt index 175df686..24acdc60 100644 --- a/jetpacker/android/feature/trip/booking_assistant/src/main/kotlin/com/example/jetpacker/feature/booking_assistant/BookingAssistantViewModel.kt +++ b/jetpacker/android/feature/trip/booking_assistant/src/main/kotlin/com/example/jetpacker/feature/booking_assistant/BookingAssistantViewModel.kt @@ -680,7 +680,13 @@ class BookingAssistantViewModel @Inject constructor( private suspend fun getFirebaseAuthToken(): String { log("getFirebaseAuthToken: getting FirebaseAuth instance") - val auth = FirebaseAuth.getInstance() + val auth = try { + FirebaseAuth.getInstance() + } catch (e: Exception) { + log("FirebaseAuth.getInstance failed: ${e.message}") + Log.e("BookingAssistant", "FirebaseAuth.getInstance failed", e) + return "" + } var user = auth.currentUser log("getFirebaseAuthToken: current user is ${user?.uid ?: "null"}") if (user == null) {