To use this API in the frontend, we will add a fetch method to mern-social/client/post/api-post.js:
const listByUser = (params, credentials) => { return fetch('/api/posts/by/'+ params.userId, { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + credentials.t } }).then(response => { return response.json() }).catch((err) => console.log(err))}
This fetch method will load the required posts for the PostList that is added to the Profile view. We will update the Profile component to define a loadPosts method that calls the listByUser fetch method.
mern-social/client/user/Profile.js:
loadPosts = (user) => { const jwt = auth.isAuthenticated() listByUser({ ...