I am using this type of codes.it is not working,
I run app in debug mode.
It stop in below lines of code.
The code lines are didn't run so it was not login
I am trying to login with the google login it was working up to the OnActivityResult (if(resultcode == Activity.RESULT_OK).
this code was referred to in Firebase Documentation.
fireBaseAuth = FirebaseAuth.getInstance()
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.client_ID))
.requestEmail()
.build()
googleSignINClient = GoogleSignIn.getClient(this@SignInActivity,gso)
googleSignin = findViewById(R.id.google_login)
googleSignin.setOnClickListener {
signIn()
}
.setOnClickListener {
startActivity(Intent(this,SignUpActivity::class.java))
}
private fun signIn()
{
val signInIntent = googleSignINClient!!.signInIntent
startActivityForResult(signInIntent,RC_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN)
{
if (resultCode == Activity.RESULT_OK)
{
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = task.getResult(ApiException::class.java)
firebaseAuthWithGoogle(account!!)
}catch (e : ApiException)
{
Log.e(TAG, "Google SignIn failed $e")
Toast.makeText(this@SignInActivity, "Google SignIn failed",Toast.LENGTH_SHORT).show()
}
}
}
}
private fun firebaseAuthWithGoogle(account: GoogleSignInAccount){
val credential = GoogleAuthProvider.getCredential(account.idToken, null)
fireBaseAuth!!.signInWithCredential(credential)
.addOnCompleteListener(this@SignInActivity) { task ->
if (task.isSuccessful){
startActivity(Intent(this@SignInActivity, MainActivity::class.java))
finish()
}
else
{
Toast.makeText(this@SignInActivity, "Authentication Failed",Toast.LENGTH_SHORT).show()
}
}
logcat snap. enter image description here