How can I fix Google OneTapClient’s errors 16 (Cannot find a matching credential)?

I’m trying to code an Android app using Jetpack Compose.
I’ve been following a tutorial to let the users authenticate with Google and, up to a few days ago, everything was working just fine.
I’ve connected my Firebase project, enabled the authentication with Google and even set the SHA-1 key. At the same time, I’ve specified my web client id and addedd the google-services.json file to Android Studio.

A few days ago, when clicking the signin button, it would’ve shown the list of Google accounts on the device or, a form to log in with Google. Now it just throws the exception without displaying anything.

This the class I’m using:

class GoogleAuthClient(
    private val context: Context,
    private val oneTapClient: SignInClient
) {
    private val auth = Firebase.auth

    suspend fun <T> Task<T>.await(): T {
        return suspendCancellableCoroutine { continuation ->
            addOnCompleteListener {
                if (it.isSuccessful) {
                    continuation.resume(it.result, null)
                } else {
                    continuation.cancel(it.exception ?: Exception("Something went wrong during await"))
                }
            }
        }
    }

    suspend fun signIn(): IntentSender? {
        val result = try {
            oneTapClient.beginSignIn(
                buildSignInRequest()
            ).await()
        } catch (e: Exception) {
            e.printStackTrace()
            if (e is CancellationException) throw e
            null
        }
        return result?.pendingIntent?.intentSender
    }

    suspend fun signInWithIntent(intent: Intent): SignInResult {
        val credential = oneTapClient.getSignInCredentialFromIntent(intent)
        val googleIdToken = credential.googleIdToken
        val googleCredentials = GoogleAuthProvider.getCredential(googleIdToken, null)
        return try {
            val user = auth.signInWithCredential(googleCredentials).await().user
            SignInResult(data = user?.run {
                UserData(
                    userId = uid,
                    username = displayName,
                    profilePicUrl = photoUrl?.toString()
                )
            }, errorMessage = null)
        } catch (e: Exception) {
            e.printStackTrace()
            if (e is CancellationException) throw e
            SignInResult(data = null, errorMessage = e.message)
        }
    }

    private fun buildSignInRequest(): BeginSignInRequest {
        return BeginSignInRequest.builder()
            .setGoogleIdTokenRequestOptions(
                GoogleIdTokenRequestOptions.builder()
                    .setSupported(true)
                    .setFilterByAuthorizedAccounts(false)
                    .setServerClientId(context.getString(R.string.def_web_client_id))
                    .build()
            )
            .setAutoSelectEnabled(true)
            .build()
    }

}

And this is the point in which I’m calling the class:

val viewModel = viewModel<SignInViewModel>()
val state by viewModel.state.collectAsState()

val launcher = rememberLauncherForActivityResult(
    contract = ActivityResultContracts.StartIntentSenderForResult(),
    onResult = {result ->
        if (result.resultCode == RESULT_OK) {
            lifecycleOwner.lifecycleScope.launch {
                val signInResult = authClient.signInWithIntent(
                    intent = result.data ?: return@launch
                )
                // Here we already got the result from the intent
                viewModel.onSigninResult(signInResult)
                if (signInResult.data != null)
                    navController.navigate(NavigationScreen.GoalSelection.name)
                else
                    Toast.makeText(context, "Something went wrong during singin.", Toast.LENGTH_LONG)
            }
        }

    }
)
GoogleSignInButton(
    state = state,
    onGoogleSignIn = {
        lifecycleOwner.lifecycleScope.launch {
            val signinIntentSender = authClient.signIn()
            launcher.launch(
                IntentSenderRequest.Builder(
                    signinIntentSender ?: return@launch
                ).build()
            )
        }
    }
)


@Composable
fun GoogleSignInButton(
    state: SignInState,
    onSigninClick: () -> Unit
) {
    val context = LocalContext.current
    LaunchedEffect(key1 = state.signInError) {
        state.signInError?.let { error ->
            Toast.makeText(
                context,
                error,
                Toast.LENGTH_LONG
            ).show()
        }
    }
    Button(onClick = onSigninClick) {
        Text(text = "Continue with Google")
    }
}

At the moment the error is catched in the .await function (called in signIn()). At completiiton it is valorized but isSuccessful is false and the result contains the exception. It seems as if the exception is directly thrown by the Task.

I really can’t wrap my head around the fact that it was working just fine a few days ago.

I’ve tried putting breakpoints here and there. I’ve isolated the result of buildSignInRequest(), hoping to find some null values. However, the result seemed correctly valorized and, all the previous steps didn’t give any problem.
I’ve also tried going back in the project history to find if there were any breaking changes but, nothing caught my eye.

Does anyone know what could be the problem here and how to fix it?

New contributor

Zay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật