0

it was created a user document in cloud firestore database while registration. User are able to login if comparison is true. problem is firebaseuser return null with FirebaseAuth.getInstance().getCurrentUser() as it's not recognized a current login user.

My question is, is it possible to map a user from user document to a firebase user? I know I can use firestore built-in authentication. but is not a good time for me to change with my deadline.

this is login code

            db.collection("users")
                    .whereEqualTo("UserName", tools.editText.get(R.id.username_txt))
                    .whereEqualTo("Password",tools.editText.get(R.id.password_txt) )
                    .get()
                    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                        @Override
                        public void onComplete( Task<QuerySnapshot> task) {
                            if (task.isSuccessful()) {
                                if(task.getResult().size()>0) {
                                    Log.w("Rabby","success");
                                    Intent i=new Intent(LoginActivity.this,HomeActivity.class);
                                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    startActivity(i);
                                }else
                                {
                                    Toast.makeText("invalid user").show();
                                }
                            } else {

                            }
                        }
                    });

after user login, I cannot get a current user coz firebase.getcurrentuser() does not know the login user. it is possible to map user to firebase user? anyone can suggest me? a million thanks

amart
  • 13
  • 3

1 Answers1

0

check if you enabled cloud firebase firestore database for more details follow the link https://codelabs.developers.google.com/codelabs/firestore-android/#0

then used following line

StorageReference storageReference = FirebaseStorage.getInstance().getReference(); FirebaseFirestore db = FirebaseFirestore.getInstance();

which create firebase firestore instance. Then used following getUid() to get current user id.

String u_id = FirebaseAuth.getInstance().getCurrentUser().getUid();

Pratiksha Shaha
  • 133
  • 1
  • 9
  • as FirebaseAuth.getInstance().getCurrentUser() return null, couldnot get getUid() as well – amart Oct 26 '19 at 13:24