April 2020
Intermediate to advanced
716 pages
18h 55m
English
In the backend, we will need an API that allows updating an existing shop in the database if the user making the request is the authorized seller of the given shop. We will first declare the PUT route that accepts the update request from the client as follows:
mern-marketplace/server/routes/shop.routes.js:
router.route('/api/shops/:shopId') .put(authCtrl.requireSignin, shopCtrl.isOwner, shopCtrl.update)
A PUT request received at the /api/shops/:shopId route first checks if the signed-in user is the owner of the shop associated with the shopId provided in the URL using the isOwner controller method, which is defined as follows:
mern-marketplace/server/controllers/shop.controller.js:
const isOwner = (req, res, ...
Read now
Unlock full access