I want, If the user is new to the app, I want to create an account for the user with a name, profile picture, and bio. How do I know is the user is registered or not? (Look at the screenshot) -
**I do below steps understand to user already have an account or not **
- First, I say user to verify their phone number with OTP,
- when it success, App will find their phone number in the firestore database, (below is coding part for the above action)
//phoneNumber: entered by user
if (phoneNumber ==
FirebaseFirestore.instance
.collection('users')
.doc('phoneNumber')) {
print("user have!!!! Show main screen");
} else {
print('no, register! get data.. textfiledssss........');
}
But the problem is, this is not working. always output no, register! get data.. textfiledssss........
There is screenshot of my firebase firestore database, ,
My steps are not good? (what I do for understanding to the user is alredy have an account or not) If there has another way to do this. please explain it. If my steps are ok, why did this happen?
CodePudding user response:
You can query the user's phone number to check if the phone number is available in the firestore or not.
FirebaseFirestore.instance
.collection('users')
.where('phoneNumber', isEqualTo: phoneNumber)
.get()
.then((value) {
if (value.docs.isEmpty) {
print('no, register! get data.. textfiledssss........');
} else {
print("user have!!!! Show main screen");
}
});