April 2020
Intermediate to advanced
716 pages
18h 55m
English
When a user follows or unfollows another user from the view, both users' records in the database will be updated in response to the follow or unfollow requests.
Set up follow and unfollow routes in user.routes.js as follows.
mern-social/server/routes/user.routes.js:
router.route('/api/users/follow') .put(authCtrl.requireSignin, userCtrl.addFollowing, userCtrl.addFollower)router.route('/api/users/unfollow') .put(authCtrl.requireSignin, userCtrl.removeFollowing, userCtrl.removeFollower)
The addFollowing controller method in the user controller will update the following array for the current user by pushing the followed user's reference into the array, as shown in the following code.
mern-social/server ...
Read now
Unlock full access