May 2018
Intermediate to advanced
470 pages
13h 54m
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.
We will 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.
mern-social/server/controllers/user.controller.js:
Read now
Unlock full access