0

My Javascript function returns undefined, even though a value exists. When I console.log() my return value, it will output the value but not return it.

function uidToUser(uid) {
        var docRef = db.collection("nfcChips").doc(uid);
        docRef.get().then(function(doc) {
            if (doc.exists) {
                user = doc.data().holder
                console.log(user) //logs correct value 
                return user; //returns undefined
            }
        }).catch(function(error) {
            console.error("Error getting2 document:", error);
            return "error";
        });
    }
Leonard Niehaus
  • 500
  • 6
  • 16

0 Answers0