如何获得Firebase密钥的值并将其存储在变量中?

时间:2019-05-27 02:22:22

标签: javascript reactjs firebase react-native firebase-realtime-database

我正在尝试获取特定用户在用户下的photoURL值,并将其保存为变量,以便我可以在操作中使用它。有什么建议吗?

我可以访问photoURL的值,但是不能将其另存为变量。

    {
      "users" : {
          "NQgSxcVKm1N3tnkykUevBM45JLn2" : {
            "name" : "Tom Hanks",
            "photoURL" : "https://firebasestorage.googleapis.com/v0/b/myapp-d0755.appspot.com/o/profilePhotos%2....",
            "receiver" : "RIXXnKMGxYRPBTe1kBUsNUV9eFL2",
            "sent" : 1557800380001,
            "status" : "pending",
            "uid" : "NQgSxcVKm1N3tnkykUevBM45JLn2"
        }
      }
    }
    export const sendMessage = ({ uid, name, text }) => {
        const { currentUser } = firebase.auth()

        // firebase.database().ref('/users/' + uid).on(('value'), function (snapshot) {
        //     const photo = snapshot.val().photoURL;
        // });

        const firstLast = firebase.auth().currentUser.displayName
        const photoURL = firebase.auth().currentUser.photoURL
        return (dispatch) => {

            firebase.database().ref(`/messageList/${currentUser.uid}/${uid}`)
                .set({ uid, name,photo:photo, text, created: firebase.database.ServerValue.TIMESTAMP })
                .then(() => {
                    firebase.database().ref(`/messageList/${uid}/${currentUser.uid}`)
                        .set({ uid: currentUser.uid, name: firstLast, text, photo: photoURL, created: firebase.database.ServerValue.TIMESTAMP })
                })
                .then(() => {
                    dispatch({
                        type: SEND_MESSAGE
                    });
                });
        };
    };

我正在尝试将其另存为可变照片,以使第一个dispatch / firebase .set起作用。

0 个答案:

没有答案