Check if value exists in firebase DB

后端 未结 4 2003
萌比男神i
萌比男神i 2020-11-29 20:24

Is there a method in firebase, which can check if value exist in DB? Firebase has method .exists(), but according to docs it checks only the keys.

I have the followi

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 21:01

    This is a similar solution if you want to check if an email exists in firebase

    firebase.app().database().ref("shops").orderByChild("email")
       .equalTo(user.email).once("value", snapshot => {
    
                const userData = snapshot.val();
    
                // Check if it is a SHOP.
                if (userData) {
                  console.log("Shop logged in!");
                  this.setState({
                    isAdminLoggedIn: false,
                    isUserLoggedIn: false,
                    isShopLoggedIn: true,
                    isNoneLoggedIn: false
                  });
    
                // Check if it is a USER.
                } else {
                  console.log("User logged in");
                  this.setState({
                    isAdminLoggedIn: false,
                    isUserLoggedIn: true,
                    isShopLoggedIn: false,
                    isNoneLoggedIn: false
                  });
                }
            });
    

提交回复
热议问题