Sunday, 2 January 2022

Google signin with firebase on Android not working

My app has been publish for a while and Google Sign in was working fine untill now. It just suddenly stopped working. I've checked everything includeing SHA-1 fingerprint, client_id etc.

Upon testing i've found out that the result activity doens't return RESULT_OK.

private lateinit var googleSignInClient: GoogleSignInClient

private var googleSigninLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){

    if(it.resultCode == RESULT_OK){
        val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
        try {
            val account = task.getResult(ApiException::class.java)
            account.idToken?.let {token->
                firebaseAuthWithGoogle(token)
            }

        } catch (e: ApiException) {
            Log.d("LOGIN_DEBUG", e.message.toString())
        }
    }else{
        //This is where the code reaches and I am getting RESULT_CODE 0 in the logs
        toast(this@MainActivity, getString(R.string.there_was_an_error))
        Log.d("LOGIN_DEBUG", it.resultCode.toString())
    }
}


val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build()

    googleSignInClient = GoogleSignIn.getClient(this, gso)


google_signin.setOnClickListener {
        val signInIntent = googleSignInClient.signInIntent

        googleSigninLauncher.launch(signInIntent)
        toast(this@MainActivity, resources.getString(R.string.please_wait))
    }

I've looked at a lot of questions but none of the solutions are working for me. Any help is greatly appreciated.



from Google signin with firebase on Android not working

No comments:

Post a Comment