InstagramClone icon indicating copy to clipboard operation
InstagramClone copied to clipboard

firestore propery undefined in fetchUsersFollowingPosts(uid)

Open AmitSrour opened this issue 4 years ago β€’ 27 comments

https://github.com/SimCoderYoutube/InstagramClone/blob/e42308ee5fc186310bab10d4f1dfc955604c842f/frontend/redux/actions/index.js#L102 This line of code in the redux action folder inside the fetchUsersFollowingPosts(uid) function is responsible for fetching the individual posts of the users that the user is following, specifically getting the uid that we looked for but within the scope of the returned promise...

it seems like the current expo and firebase SDK doesn't recognize what the .EP property is.

according to the firestore api reference there is no EP property, could this be a specific reference into your own development environment or is it deprecated?

for reference FireStore: https://firebase.google.com/docs/reference/node/firebase.firestore Query.get(): https://firebase.google.com/docs/reference/node/firebase.firestore.Query#get QuerySnapshot: https://firebase.google.com/docs/reference/node/firebase.firestore.QuerySnapshot QueryDocumentSnapshot: https://firebase.google.com/docs/reference/node/firebase.firestore.QueryDocumentSnapshot

my package.json: "@react-native-community/masked-view": "0.1.10", "@react-navigation/bottom-tabs": "^5.11.7", "@react-navigation/material-bottom-tabs": "^5.3.13", "@react-navigation/native": "^5.9.2", "@react-navigation/stack": "^5.14.1", "expo": "~40.0.0", "expo-camera": "~9.1.0", "expo-image-picker": "^10.0.0", "expo-status-bar": "~1.0.3", "firebase": "^8.2.4", "react": "16.13.1", "react-dom": "16.13.1", "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz", "react-native-gesture-handler": "^1.9.0", "react-native-paper": "^4.7.1", "react-native-reanimated": "~1.13.0", "react-native-safe-area-context": "3.1.9", "react-native-screens": "~2.15.2", "react-native-vector-icons": "^8.0.0", "react-native-web": "~0.13.12", "react-redux": "^7.2.2", "redux": "^4.0.5", "redux-thunk": "^2.3.0"

Youtube timestamp: https://youtu.be/1hPgQWbWmEk?t=14880 Thanks a lot! I'm a huge fan

AmitSrour avatar Feb 02 '21 13:02 AmitSrour

just figured out this is a repost of https://github.com/SimCoderYoutube/InstagramClone/issues/16 from a week ago. I'm going to leave this open in case I can find a solution / or to be able to merge a solution

AmitSrour avatar Feb 02 '21 14:02 AmitSrour

Have you found any solutions?

cyber-portfolio avatar Mar 01 '21 09:03 cyber-portfolio

Hi!

I have tried to emulate the problem without success. But I'm trying to push an update for this ASAP.

The problem arises because there is no documented way of getting the ID of each object from the querySnapshot when you get the doc using an onSnapshot query. This is the "hack" I found that allows this. I'll be trying to push an update for this this week

SimCoderYoutube avatar Mar 01 '21 19:03 SimCoderYoutube

Guys have you solved this??

Yeghishe-Karapetyan avatar Mar 13 '21 14:03 Yeghishe-Karapetyan

Hi!

I have tried to emulate the problem without success. But I'm trying to push an update for this ASAP.

The problem arises because there is no documented way of getting the ID of each object from the querySnapshot when you get the doc using an onSnapshot query. This is the "hack" I found that allows this. I'll be trying to push an update for this week

I'm pretty sure you can get the ID from the document reference from the docs collection snapshot.docs[0].ref.path.split('/')[1]

digimbyte avatar Mar 13 '21 14:03 digimbyte

it gives an error friend @digimbyte

Yeghishe-Karapetyan avatar Mar 18 '21 17:03 Yeghishe-Karapetyan

i have the same problem

zacharie85 avatar Apr 07 '21 01:04 zacharie85

snapshot.docs[0].ref.path.split('/')[1]

This is the solution!!!! I am getting the UID now. Still had some errors with props.usersState.users but I think this is a different problem.

JoshValencia avatar Apr 18 '21 08:04 JoshValencia

Thanks SimCoderYoutube/InstagramClone

On Sun., Apr. 18, 2021, 5:39 a.m. Jushua Valencia, @.***> wrote:

snapshot.docs[0].ref.path.split('/')[1]

This is the solution!!!!

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SimCoderYoutube/InstagramClone/issues/19#issuecomment-821955683, or unsubscribe https://github.com/notifications/unsubscribe-auth/APZJ2JPPCBETOGMIXFQWKATTJKLDRANCNFSM4W6VPCUA .

zacharie85 avatar Apr 18 '21 09:04 zacharie85

for reference, I run a Firebase Community on Discord - we had a user who had the same issue, the error proceeding is related to something else in the project. https://discord.firebase.me/

digimbyte avatar Apr 18 '21 10:04 digimbyte

Hi, here is the error I am getting[image: Capture.PNG]

Le dim. 18 avr. 2021 Γ  07:21, DIGI Byte @.***> a Γ©crit :

for reference, I run a Firebase Community on Discord - we had a user who had the same issue, the error proceeding is related to something else in the project. https://discord.firebase.me/

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SimCoderYoutube/InstagramClone/issues/19#issuecomment-821968811, or unsubscribe https://github.com/notifications/unsubscribe-auth/APZJ2JIA4HLK4U2ITRZH3KLTJKXCJANCNFSM4W6VPCUA .

zacharie85 avatar Apr 19 '21 16:04 zacharie85

Getting the same error :(

chaitanya1731 avatar Apr 24 '21 17:04 chaitanya1731

A potential solution is to use:

const uid = snapshot.docs[0].ref.path.split('/')[1];

and put that line^ and the rest of the code in that function in a try catch block. The line above will throw an error if there is no documents (posts), so for users where this throws an error, just catch, and do nothing since its pointless to get the posts of a user with no posts.

cerovcecblaze avatar May 02 '21 06:05 cerovcecblaze

I think you should console.log(snapshot) for yourself and try to find the segments data based on the console.log, the snapshot data might be different because firebase might update their way to display the snapshot. For my part i was able to retrieve the data from snapshot..query.C.path.segments[1];

minhquan0902 avatar May 13 '21 18:05 minhquan0902

snapshot.docs[0].ref.path.split('/')[1];

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'snapshot.docs[0].ref')] also give error after using this code

gxanshu avatar Jul 20 '21 12:07 gxanshu

is there is any solution ??

gxanshu avatar Jul 20 '21 12:07 gxanshu

That would only mean that you aren't actually retrieving any files, since it would be undefined. I think this issue is effectively closed - the project would need a patch to make this more standard and integrated.

digimbyte avatar Jul 21 '21 03:07 digimbyte

well i got the answer from the internet you can check it out form stackoverflow πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡ https://stackoverflow.com/a/68456060/14078264

gxanshu avatar Jul 21 '21 04:07 gxanshu

not sure what you mean: I posted that same code above and you claimed it gave you errors and you then also posted it on SO?

digimbyte avatar Jul 21 '21 04:07 digimbyte

well you are right but this code snapshot.docs[0].ref.path.split('/')[1]; is not working for me without this change dispatch(fetchUserFollowingPosts(user.id)) to dispatch(fetchUserFollowingPosts(user.uid))

gxanshu avatar Jul 21 '21 11:07 gxanshu

that's why i post this

gxanshu avatar Jul 21 '21 11:07 gxanshu

that's because there is no such thing as 'id' on the user.

digimbyte avatar Jul 21 '21 13:07 digimbyte

yes that's right

gxanshu avatar Jul 21 '21 17:07 gxanshu

Mine was snapshot.query._.C_.path.segments[1], definitely need to log snapshot and look for yourself.

Jenpaulino3 avatar Jul 28 '21 05:07 Jenpaulino3

Hi guys, while implementing this practice app, I also came across the section in code where we needed to extract the specific uid for each query by using 'const uid = snapshot.query.EP.path.segments[1]'. I however found that unnecessary, as closure in javascipt binds inner functions to outer functions lexical scope, ensuring they have access to parent function variables. Hence, referencing the uid variable means that we will always get the correct reference. Please read more about it in the attached link, I am open to corrections if I am getting it wrong, thanks. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures

olawalethefirst avatar Jul 29 '21 12:07 olawalethefirst

well you are right but this code snapshot.docs[0].ref.path.split('/')[1]; is not working for me without this change dispatch(fetchUserFollowingPosts(user.id)) to dispatch(fetchUserFollowingPosts(user.uid))

Please where did you make the change as I don't seem to find this dispatch(fetchUserFollowingPosts(user.id)) line in my code, on;y dispatch(fetchUsersFollowingPosts(uid)) in the fetchUsersData function.

Tolu-pr avatar Jun 13 '22 19:06 Tolu-pr

I think you should console.log(snapshot) for yourself and try to find the segments data based on the console.log, the snapshot data might be different because firebase might update their way to display the snapshot. For my part i was able to retrieve the data from snapshot..query.C.path.segments[1];

Yeah, did this and it worked

billlouis avatar Jun 16 '23 20:06 billlouis