Skip to content

Commit

Permalink
refactor: Update middleware call in comments.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pnijhara committed Jun 14, 2020
1 parent 403dcc2 commit de03037
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions routes/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const express = require("express")
const router = express.Router()
const foodData = require("../models/foodup")
const Comment = require("../models/comment")

const middleware = require("../middleware")

//Comments route//
router.get("/FoodUp/:id/comments/new", isLoggedIn, function(req, res){
router.get("/FoodUp/:id/comments/new", middleware.isLoggedIn, function(req, res){
foodData.findById(req.params.id, function(err, foodData){
if(err){
console.log(err)
Expand All @@ -15,7 +15,7 @@ router.get("/FoodUp/:id/comments/new", isLoggedIn, function(req, res){
})
})

router.post("/FoodUp/:id/comments", isLoggedIn,function(req, res){
router.post("/FoodUp/:id/comments", middleware.isLoggedIn,function(req, res){
foodData.findById(req.params.id, function(err, foodData){
if(err){
console.log(err)
Expand All @@ -38,12 +38,4 @@ router.post("/FoodUp/:id/comments", isLoggedIn,function(req, res){
})
})

//isLoggedIn Middleware
function isLoggedIn(req, res, next){
if(req.isAuthenticated()){
return next()
}
res.redirect("/login")
}

module.exports = router

0 comments on commit de03037

Please sign in to comment.