Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
req.body is empty when apply middleware to a GET route

I write a router for authentication and a middleware to parse redirect parameter and save in session. But when parsing query parameters, both req.body and req.params are empty.

router.js

/* Route for Facebook login. This is the only login option for now. */

var router = require('express').Router();
var passport = require('passport');
var redirect = require('../middlewares/redirect');

/**
 * facebook oauth
 */
router.get('/facebook', redirect.parse(), passport.authenticate('facebook'));

redirect.js

/**
 * save the redirect parameter to session
 *
 * @param {Object} options options for the middleware
 */
module.exports.parse = function (options) {
  return function (req, res, next) {
    console.log(req.body);
    console.log(req.params);
    if (req.body.redirect) {
      req.session.redirect = req.body.redirect;
      console.log(req.body.redirect);
      console.log(req.session.redirect);
      req.session.save();
    }
    next();
  };
};

When I call /auth/facebook?redirect=/groups, the output is:

{}
{}

The code is on Github https://github.com/guoyunhe/shrgrp

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You are calling GET and expecting data from req.body which is not gonna work

With GET call you can get data in two ways:

if it is parameter then you can get in req.params

If it is query string then you can get in req.query

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!