I'm using Firebase Data Connect and Firebase Authentication in my Android app. I also have Firebase App Check integrated, but it is currently set to unenforced mode.
Users are required to sign in successfully to my app using Firebase Authentication, before they call any Firebase Data Connect queries/mutations. I check this by verifying Firebase.auth.currentUser != null
when my app launces.
I am using the latest Firebase Data Connect SDK version 16.0.1.
Randomly, when a logged-in user performs an action that triggers a Data Connect function call, the app crashes and logs the following gRPC error:
Fatal Exception: e9.p0: UNAUTHENTICATED: unauthenticated: this operation requires a signed-in user
at io.grpc.Status.asException(Status.java:548)
at io.grpc.kotlin.ClientCalls$rpcImpl$1$1$1.onClose(ClientCalls.kt:300)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:574)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:72)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:742)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:723)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at com.google.firebase.concurrent.CustomThreadFactory.lambda$newThread$0(CustomThreadFactory.java:47)
at java.lang.Thread.run(Thread.java:1012)
This error is intermittent and I haven't been able to find a consistent way to reproduce it.
The stack trace provided above does not reference any of my specific application classes or methods directly related to the Data Connect call initiation. It points to internal io.grpc and com.google.firebase.concurrent classes, suggesting the failure occurs deeper within the Firebase SDK or gRPC layer during the authenticated request processing.
The Android functions I use to interact with Data Connect were auto-generated by the Firebase Data Connect tooling based on my GraphQL defined queries and mutations. Because the error seems internal and the Data Connect functions are auto-generated, I'm unsure which specific parts of my code are most relevant to debugging this UNAUTHENTICATED error.
If specific parts of my code would be helpful, please let me know in the comments, and I will update the question with the relevant snippets.
data class UserData(
val userId: String,
val username: String?,
val profilePictureUrl: String?
)
class GoogleAuthUiClient(
private val context: Context,
) {
private val auth = Firebase.auth
// Gets the signed in user details
fun getSignedInUser() = auth.currentUser?.run {
UserData(uid, displayName, photoUrl?.toString())
}
// Some other functions for signing in with CredentialManager...
}
// Main app composable with some irrelevant code removed
// Checks if user is null to show Home screen for logged in users
// and Onboarding (Login) screen for users that are not logged in
@Composable
fun MyApp(
lifecycleScope: LifecycleCoroutineScope,
googleAuthUiClient: GoogleAuthUiClient,
application: android.app.Application
) {
val navController = rememberNavController()
val user = googleAuthUiClient.getSignedInUser()
if (user != null) {
DataConnectRepository.updateSignInInfo(user.username)
}
val startDestination =
if (user != null) {
Home
} else {
Onboarding
}
MyAppNavHost(
startDestination = startDestination,
lifecycleScope = lifecycleScope,
googleAuthUiClient = googleAuthUiClient
)
}
MainActivity.kt
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private val googleAuthUiClient by lazy {
GoogleAuthUiClient(
context = this
)
}
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
FirebaseApp.initializeApp(this)
if (BuildConfig.DEBUG) {
Firebase.appCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance(),
)
} else {
Firebase.appCheck.installAppCheckProviderFactory(
PlayIntegrityAppCheckProviderFactory.getInstance(),
)
}
setContent {
MyAppTheme {
MyApp(
lifecycleScope = lifecycleScope,
googleAuthUiClient = googleAuthUiClient,
application = application
)
}
}
}
}
DataConnectRepository.kt
object DataConnectRepository {
private val connector: DefaultConnector = DefaultConnector.instance
// init {
// if (BuildConfig.DEBUG) {
// connector.dataConnect.useEmulator()
// }
// }
fun updateSignInInfo(displayName: String?) {
CoroutineScope(Dispatchers.IO).launch {
try {
connector.upsertUser.execute(displayName!!)
} catch (e: Exception) {
Log.i("User ID", Firebase.auth.currentUser?.uid.toString())
Firebase.crashlytics.recordException(e)
e.printStackTrace()
}
}
}
suspend fun getActiveSubscriptions(): List<GetMyActiveSubscriptionsQuery.Data.GooglePlaySubscriptionsItem> {
try {
return connector.getMyActiveSubscriptions.execute().data.googlePlaySubscriptions
} catch (e: FirebaseNetworkException) {
e.printStackTrace()
throw NoInternetConnectionException(e)
} catch (e: Exception) {
if (e.cause is UnknownHostException || e.cause?.cause is UnknownHostException) {
throw NoInternetConnectionException(e)
} else {
Log.i("User ID", Firebase.auth.currentUser?.uid.toString())
e.printStackTrace()
throw e
}
}
}
class NoInternetConnectionException(cause: Throwable?) :
Exception("No internet connection available", cause)
}
I can confirm that the user id of both User ID
log statements is non-null when a crash occurs.
Has anyone experienced this error before, or have any ideas what to do to solve it?
This is a legitimate bug in the Data Connect Android SDK. A fix has been created and will be available in the 16.0.3 release circa end-of-June 2025: https://github.com/firebase/firebase-android-sdk/pull/7001. The root cause was a race condition in the way that the FirebaseDataConnect
object retrieved its handle to the FirebaseAuth
instance.
Unfortunately, there is no good workaround since the bug is deep in the SDK's code. The only mitigation I can think of is to issue a query/mutation on the newly-created FirebaseDataConnect
object that requires authentication: if the operation succeeds then the bug will not affect that FirebaseDataConnect
object and you can use it; if, however, the operation fails with UNAUTHENTICATED then close the FirebaseDataConnect
object and try again, hoping for better luck with the race condition.
Thank you for the thorough bug report. My sincere apologies for the inconvenience this has caused you.