Advertisements

FA GOOGLE LoginAnonymous-LinkAccount-MainLogic

    if (currentUser!= null)
    {
        if (!mEmail.isEmpty() || !mPassword.isEmpty())  //checking email,password editText are not empty
        {
            AuthCredential credential = EmailAuthProvider.getCredential(mEmail,mPassword);
            currentUser.linkWithCredential(credential)              //linkWithCredential is a method provided by Firebase just to link the credentials
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>()
                    {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task)
                        {
                            if (task.isSuccessful())
                                {
                                    Toast.makeText(LinkAccount.this,"account linked",Toast.LENGTH_SHORT).show();
                                }
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.e("TAG2",e.getMessage());
                        }
                    });
        }
    }