Skip to content

Commit

Permalink
realtime update of liked posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank-Gu-81 committed Feb 2, 2025
1 parent 1d3cdf8 commit 299df13
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@ function App() {
setUserEmail(curUser?.email);
setProfilePic(curUser?.photoURL);
setAuthLoaded(true);
const docRef = doc(db, "users", curUser.uid);
onSnapshot(docRef, (doc) => {
if (doc.exists()) {
const data = doc.data();
setLikedPosts(data.likedPosts || []);
} else {
console.log("No such document!");
}
});
console.log("user's liked posts: ", likedPosts);
} else {
setUser(null);
setUserEmail(null);
setProfilePic(null);
setAuthLoaded(true);
setLikedPosts([]);
}
})

Expand Down

0 comments on commit 299df13

Please sign in to comment.