1

i created a standard login and signup page and i added an alternative to sign in with a google account using the custom GogleSignInButton.

The button works welll. am able to select a google account and sign in but the credentials do not reflect in the firebase authentication console nor does it bring up the signup activity for new users like it does when using the standard firebase UI. I already have a working login with email and password(if it helps).

I would like help in immplementing the storage of credentials and signing up new users with google accounts.

From the image below you can see there are no gmail accounts enter image description here

SignInButton signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);

    GoogleSignInOptions gso = new 
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);





    if (mAuth.getCurrentUser() != null) {
        startActivity(new Intent(LoginActivity.this, 
MainActivity.class));
        finish();
    }

        signInButton.setOnClickListener(this);



    private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.sign_in_button:
            signIn();
            break;

    }

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
}

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI.
        startActivity(new Intent(LoginActivity.this,MainActivity.class));
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
        Toast.makeText(this, "Authentication Failed", Toast.LENGTH_SHORT).show();
    }

}

@Override
public void onStart() {
   // Check if user is signed in (non-null) and update UI accordingly.
   GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
   if(account != null) {
       startActivity(new Intent(LoginActivity.this,MainActivity.class));
   }
    super.onStart();
}
JoshM
  • 111
  • 8
  • Potential [duplicate](https://stackoverflow.com/questions/47285784/firebase-android-auto-login) - not enough reputation to flag. –  Aug 27 '19 at 17:12
  • That is a different problem. i only wnt firabase to store the google logins. because it can store other emails. but when one signs in using gmail it does not reflect the credentials in firebase – JoshM Aug 27 '19 at 17:37

0 Answers0