It seems that before firebase is able to get the current user authentication data such as the email used for login, it attempts to call
firestore.collection("users").doc(firebase.auth().currentUser.email).onSnapshot(function(doc) {
console.log("check")
});
the thing is, it requires the current user's email to access the correct document in the collection from within the database.
is there any way to circumvent this and to wait until currentUser defined?
If your code depends on having an authenticated user, you should run it in an onAuthStateChanged
callback. For example:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
firestore.collection("users").doc(firebase.auth().currentUser.email).onSnapshot(function(doc) {
console.log("check")
});
}
});
Also see the Firebase documentation on getting the authenticated user .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.