My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

ExpressJS, protected routes.

Imran Khan's photo
Imran Khan
·Jan 27, 2018

Hi everyone,

Is there better way to have protected routes, in expressjs, I'm sensing some code messy while code expands while i'v to repeat the middleware to all the routes.

Any better way to initialize like in Laravel group routes. My code below.

router.post("/create", controller.authController.isAuthenticated, controller.articleController.create)
router.get("/edit/:id", controller.authController.isAuthenticated, controller.articleController.edit) 
router.put("/update/:id", controller.authController.isAuthenticated, controller.articleController.update)
router.delete("/delete/:id", controller.authController.isAuthenticated, controller.articleController.delete)