I'm trying to use firebase.database().ref('/friends/requests/').equalTo(currentUser.uid) in . the below code to retrieve the data only for the current user that is signed in. I'm very confused on how to filter it by user name and tried multiple scenarios to no avail.
I already tried using the equalTo method from firebase but cannot seem to get it to work. How can I access the second child of my data structure and still retrieve the data beneath it? the error is in the friendRequestFetch function.
JSON
{ "requests" : { "RIXXnKMGxYRPBTe1kBUsNUV9eFL2" : { "NQgSxcVKm1N3tnkykUevBM45JLn2" : { "name" : "Tom Hanks", "photoURL" : "https://firebasestorage.googleapis.com/v0/b/myapp-d0755.appspot.com/o/profilePhotos%2FNQgSxcVKm1N3tnkykUevBM45JLn2?alt=media&token=7822d763-e1e0-421e-88bf-836b34184c2c", "receiver" : "RIXXnKMGxYRPBTe1kBUsNUV9eFL2", "sent" : 1557800380001, "status" : "pending", "uid" : "NQgSxcVKm1N3tnkykUevBM45JLn2" } } } } Code
export const sendFriendRequest = (item) => { const { currentUser } = firebase.auth() return (dispatch) => { firebase.database().ref(`/friends/requests/${item.uid}/${currentUser.uid}`)//sting interpolation .set({ uid: currentUser.uid, //userName: firebase.database().ref(`/users/${currentUser.uid}`).snapshot.val().userName, name: currentUser.displayName, photoURL: currentUser.photoURL, status: "pending", sent: firebase.database.ServerValue.TIMESTAMP }) .then(() => { dispatch({ type: SEND_FRIEND_REQUEST }); }); }; }; export const friendRequestFetch = () => { const { currentUser } = firebase.auth() return (dispatch) => { firebase.database().ref('/friends/requests') .on('value', snapshot => { snapshot.forEach(child => { //anytime we get any value call function with an object thats describing the data thats sitting in there dispatch({ type: FRIEND_REQUEST_FETCH_SUCCESS, payload: child.val() // this is how we get access to the data at this ref }); }); }); }; }; I need the child vals but only for the current user that is signed in.