图像未定义(Firebase存储 - React Native)

时间:2018-01-09 06:22:44

标签: image firebase react-native firebase-storage

问题: 我能够成功将图像上传到firebase存储,但是当我尝试注销,然后再次登录时,我被困在登录页面上。几分钟后出现此错误

enter image description here

这是我提取图像和登录的代码

 if (currentUser != null) {
          uid = currentUser.uid;
          const db = firebase.firestore();
          const docRef = db.collection("users").doc(uid);
          console.log("uid")
          console.log(uid)
          console.log("currentUser")
          console.log(currentUser)
          console.log("docRef")
          console.log(docRef)
          docRef.get().then((doc) => {
            console.log("doc");
            console.log(doc);
            if (doc.exists) {
              console.log("Document data:", doc.data());
               const userData = doc.data();

              const imageRef = firebase.storage().ref(`/userProfilePictures/${uid}`).child('profile.jpg');
              imageRef.getDownloadURL().then(function(url) {
              dispatch({ type: GET_PROFILE_PICTURE, payload: url })
              dispatch({ type: GET_USER_DATA, payload: userData});
              Actions.home();

            }).catch((error) => {
              dispatch({type: GET_PROFILE_PICTURE, payload: ''})
              console.log(error);
            })
            } else {
              console.log("No such document!");
            }
          }).catch((error) => {
            console.log("Error getting document:", error);
          });

        }else {
          console.log('something went wrong');
        }
      })
      .catch((error) => {
        loginUserFail(dispatch)
        const errorCode = error.code;
        const errorMessage = error.message;
        console.log(errorMessage);
      });

再次登录后,似乎用户已通过身份验证,但无法执行此行docRef.get()。然后((doc)=&gt; {console.log上没有错误。< / p>

然后,如果您再次尝试重新加载,则再次登录即可看到新上传的图像。

0 个答案:

没有答案