ed-roh / mern-social-media

Complete React MERN Full Stack Social Media App
992 stars 859 forks source link

Add/remove friend and other user profile view not working #10

Open Prasun60 opened 1 year ago

Prasun60 commented 1 year ago

socialmedia Add/remove friend option is not working, on inspecting its saying -- friends.find() is not function and friends.map() is not a function in the Friend.jsx file in the component folder at line 22. Also viewing other person's profile is not working.

selim27000 commented 1 year ago

I had the same problem, issue : clear cache. if you console.log(friends) that return a error "'ID or POST or lastName...' missing". friends don't return data, I heard in the video that some data was stored in the cache system, so, probably a synchronization problem.. Yet, i don't know what is the real reason.. I'm waiting for an explanation and correction to this bug haha

clear cache will allow you to continue working in the meantime 😅😀

Prasun60 commented 1 year ago

I figured out that its working fine when when we are trying to visit the profile of a user which have logged in by us previously and and can also add/ remove them as friends, but the same is not working when trying with the by default shown user

Funix565 commented 1 year ago

Dear @Prasun60

I had the same Uncaught TypeError: friends.find is not a function. In my case, Steve Ralph had in his friends array the id, which didn't exist. That's because my user added him to friends. So Steve Ralph's id was in my user's friends array. And my id was in Steve Ralph's friends array. Then I deleted my created user via MongoDB. And it turned out that Steve Ralph had an id of a user that didn't exist. This code is trying to find info about the user and fails: https://github.com/ed-roh/mern-social-media/blob/60cc6b8f4564f1fbe7a787e9b4ce3e88263cc023/server/controllers/users.js#L19-L21

That affects the frontend client code here: https://github.com/ed-roh/mern-social-media/blob/60cc6b8f4564f1fbe7a787e9b4ce3e88263cc023/client/src/scenes/widgets/FriendListWidget.jsx#L41-L49

So, my solution was to drop all collections and populate them again: https://github.com/ed-roh/mern-social-media/blob/60cc6b8f4564f1fbe7a787e9b4ce3e88263cc023/server/index.js#L65-L67