0

I'm new to firebase and I don't know how to compare the data in the input fields with the data in firestore. I've searched the firestore documentation for this but can't seem to find it. Would really appreciate the help !

This is the image of the data:

https://i.stack.imgur.com/zAlEG.jpg

  db.collection("kaprixlogin")
.add({
  users: {
    email: "adeel@yahoo.com",
    password: "nova",
  },
})
.then(function (docRef) {
  console.log("Document written with ID: ", docRef.id);
})
.catch(function (error) {
  console.error("Error adding document: ", error);
});

db.collection("kaprixlogin")
  .get()
  .then((snap) => {
    snap.forEach((doc) => {
      console.log(doc.data());
      console.log(doc.id);
    });
 });
<form method="POST" action="">
    <div class="form-label-group">
        <input type="email" id="useremail" name="mail" class="form-control" placeholder="Email" required autofocus>
        <label for="useremail">Email address</label>
    </div>
    
    <div class="form-label-group">
        <input type="password" id="inputPassword" name="pass" class="form-control" placeholder="Password" required>
        <label for="inputPassword">Password</label>
    </div>
</form>
mix3d
  • 4,122
  • 2
  • 25
  • 47
Code_war
  • 15
  • 6

1 Answers1

0

As mentioned here the way to do this is to have a different structure, where the login (in your case I think it would be the email) as the id of the document, This way you can query for the document with ID "adeel@yahoo.com".

This will make the queries to firestore a lot more efficient, as you will only need to read one document per login, and it will also enforce the unicity of this field.

Additionally for the password it is not recommended to store them in plain text, so I would recommend you to store a hash of the password, and compare with the hash.

Soni Sol
  • 2,367
  • 3
  • 12
  • 23