Route

In the backend, we will add a POST route in game.routes.js, that verifies that the current user is signed in and authorized, and then creates a new game with the game data passed in the request.

mern-vrgame/server/routes/game.routes.js:

router.route('/api/games/by/:userId')    .post(authCtrl.requireSignin,authCtrl.hasAuthorization, gameCtrl.create)

To process the :userId param and retrieve the associated user from the database, we will utilize the userByID method from the user controller. We will also add the following to the game routes, so the user is available in the request object as profile.

mern-vrgame/server/routes/game.routes.js:

router.param('userId', userCtrl.userByID)

The game.routes.js file will be very similar to the user.routes ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.