0
我想在Cloud Firestore中創建用戶數據庫,並將電子郵件作爲每個用戶的唯一ID。用戶應該在collection
,每個用戶是document
。檢查用戶是否存在於Firestore
這是我的檢查,如果用戶在登錄活動存在:
FirebaseFirestore db = FirebaseFirestore.getInstance();
final DocumentReference userRef = db.collection("users").document(email);
userRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
Toast.makeText(LoginActivity.this, task.getResult().toString(),
Toast.LENGTH_SHORT).show();
if (document != null) {
//The user exists...
}
else {
//The user doesn't exist...
}
}
}
else
connectionErrorActivity();
}
});
的數據庫是空的,因爲你可以看到:
我的問題是, document
從不爲空,即使數據庫爲空也很難。toast
顯示字符串值document
是:[email protected]
。
這是正確的方法嗎?我能做些什麼來解決它?