Ankit Jaishwal
Ankit Jaishwal

Reputation: 526

Route.post() requires a callback function but got a [object Undefined] while using Passport Authentication

var authenticate = require('../authenticate');
const dishRouter = express.Router();

dishRouter.use(bodyParser.json());

dishRouter.route('/')
.get((req,res,next) => {
    Dishes.find({})
    .then((dishes) => {
        res.statusCode = 200;
        res.setHeader('Content-Type', 'application/json');
        res.json(dishes);
    }, (err) => next(err))
    .catch((err) => next(err));
})
.post(authenticate.verifyUser, (req, res, next) => {
    Dishes.create(req.body)
    .then((dish) => {
        console.log('Dish Created ', dish);
        res.statusCode = 200;
        res.setHeader('Content-Type', 'application/json');
        res.json(dish);
    }, (err) => next(err))
    .catch((err) => next(err));
})

Getting error at .post() function. I'm using authenticate.verifyUser to authenticate the user using Passport-jwt.Error

Upvotes: 1

Views: 45

Answers (1)

Ankit Jaishwal
Ankit Jaishwal

Reputation: 526

Solved! It was just a version issue. After updating the express it worked!

Upvotes: 1

Related Questions