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
は決してnullではなく、データベースが空であっても大丈夫です。toast
は、document
の文字列値が[email protected]
であることを示しています。
これは正しい方法ですか?それを修正するために私は何ができますか?