I'm I'm developing an Android app using Firebase Authentication (email/password) with Jetpack Compose and Kotlin. The app stores user data locally in DataStore and sets a loggedIn flag to true after successful login and email verification.
2025-08-03 10:39:59.094 12114-12114 FirebearStorageCryptoHelper com.example.pawgress E Exception encountered during crypto setup: Keystore cannot load the key with ID: firebear_main_key_id_for_storage_crypto... 2025-08-03 10:39:59.094 12114-12114 FirebearStorageCryptoHelper com.example.pawgress E KeysetManager failed to initialize - unable to decrypt data 2025-08-03 10:39:59.095 12114-12114 PawgressApplication com.example.pawgress D Firebase Auth initialized, currentUser: null 2025-08-03 10:39:59.904 12114-12114 SplashScreen com.example.pawgress D Auth state changed: null Checking local session: userId=bU36t4SAe8fDqrpCxhMfNS2SlKm1, flag=true 2025-08-03 10:40:01.920 12114-12114 UserRepository com.example.pawgress D Has local user data: true
2025-08-03 10:39:59.094 12114-12114 FirebearStorageCryptoHelper com.example.pawgress E Exception encountered during crypto setup: Keystore cannot load the key with ID: firebear_main_key_id_for_storage_crypto... 2025-08-03 10:39:59.094 12114-12114 FirebearStorageCryptoHelper com.example.pawgress E KeysetManager failed to initialize - unable to decrypt data
2025-08-03 10:39:59.095 12114-12114 PawgressApplication com.example.pawgress D Firebase Auth initialized, currentUser: null
2025-08-03 10:39:59.904 12114-12114 SplashScreen com.example.pawgress D Auth state changed: null Checking local session: userId=bU36t4SAe8fDqrpCxhMfNS2SlKm1, flag=true
2025-08-03 10:40:01.920 12114-12114 UserRepository com.example.pawgress D Has local user data: true
*WhatWhat I've Tried*Tried
firebaseAuth.addAuthStateListener { auth ->
Log.d("PawgressApplication", "Auth state changed: ${auth.currentUser}")
}
while (firebaseUser == null && retries < maxRetries) {
firebaseUser = firebaseAuth.currentUser
delay(1000)
retries++
}
var firebaseUser = firebaseAuth.currentUser
var retries = 0
val maxRetries = 10
val retryDelay = 2000L
Log.d("SplashScreen", "🔍 Initial Firebase user: ${firebaseUser?.uid}")
var authStateReceived = false
val authStateListener = FirebaseAuth.AuthStateListener { auth ->
firebaseUser = auth.currentUser
authStateReceived = true
Log.d("SplashScreen", "🔄 Auth state changed: ${firebaseUser?.uid}")
}
firebaseAuth.addAuthStateListener(authStateListener)
while (!authStateReceived && retries < maxRetries) {
Log.d("SplashScreen", "🔄 Waiting for auth state, retry $retries/$maxRetries")
delay(retryDelay)
retries++
}
firebaseAuth.removeAuthStateListener(authStateListener)
val safeUser = firebaseUser
if (safeUser != null) {
try {
safeUser.reload().await()
Log.d("SplashScreen", "✅ Firebase user reloaded: ${safeUser.uid}, verified: ${safeUser.isEmailVerified}")
} catch (e: Exception) {
Log.e("SplashScreen", "Error reloading Firebase user: ${e.message}")
}
}
val localSessionValid = userRepository.hasValidLocalSession()
val localUser = userRepository.getUser().first()
val isLoggedIn = safeUser != null &&
safeUser.isEmailVerified &&
localUser != null &&
safeUser.uid == localUser.id &&
localSessionValid
val hasLocalUser = userRepository.hasLocalUserData()
Log.d("SplashScreen", "📊 Final state - firebaseUser: ${safeUser?.uid}, isLoggedIn: $isLoggedIn, hasLocalUser: $hasLocalUser")
if (isLoggedIn && hasLocalUser) {
val surveyCompleted = userRepository.isSurveyCompleted().first()
val petNamed = userRepository.isPetNamedFlow().first()
Log.d("SplashScreen", "📋 Survey completed: $surveyCompleted, Pet named: $petNamed")
when {
!surveyCompleted -> onTimeout("survey/1")
!petNamed -> onTimeout("pet_naming")
else -> onTimeout("home")
}
} else {
Log.w("SplashScreen", "⚠️ Incomplete login - redirecting to onboarding")
onTimeout("onboarding")
}
}