I am trying to set the verified field to true in my firestore database after authenticating the user. `I am able to get the query working but once i try and update it, i get this TypeError
UnhandledPromiseRejectionWarning: TypeError: firestore.collection(...).doc is not a function
Here is my full code.
app.post("/signIn", async (req, res) => {
var email = req.body.email
var password = req.body.password
var response = {}
response["errors"] = []
response["feedback"] = []
// Authenticate User
await firebaseAuth.signInWithEmailAndPassword(firebaseAuth.getAuth(), email, password) .then(async (userCredential) => {
const user = userCredential.user
if (user.emailVerified) {
// Get Doc
const q = firestore.query(firestore.collection(db, "users"), where("user_email", "==", email));
const querySnapshot = await firestore.getDocs(q)
querySnapshot.forEach(async(doc) => {
console.log(doc.id)
// Update Field
const res = await firestore.collection(db, "users").doc(doc.id).update({verified: true})
})
response["feedback"].push("Authenticated")
} else {
response["errors"].push("Not Verified Email")
}
})
.catch((error) => {
console.log(error.code)
console.log(error.message)
response["errors"].push(error.code)
})
console.log(response)
res.send(JSON.stringify(response))
})
I've been stuck at this for hours now. Also tried updating it through
const userRef = await firestore.doc(firestore.collection(db, "users"), doc.id)
const res = await userRef.update({verified: true})