In the backend, we will add a PUT route that allows an authorized seller to edit one of their shops.
mern-marketplace/server/routes/shop.routes.js:
router.route('/api/shops/:shopId') .put(authCtrl.requireSignin, shopCtrl.isOwner, shopCtrl.update)
The isOwner controller method ensures that the signed-in user is actually the owner of the shop being edited.
mern-marketplace/server/controllers/shop.controller.js:
const isOwner = (req, res, next) => { const isOwner = req.shop && req.auth && req.shop.owner._id == req.auth._id if(!isOwner){ return res.status('403').json({ error: "User is not authorized" }) } next()}
The update controller method will use formidable and fs modules as in the create controller method discussed earlier, ...