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

174
Views
Page displays 'null' after authentication

I'm creating a simple PWA to draw in multiple data sources into one application. I'm currently trying to set up authentication using a combination of passport and the twitter-strategy.

After the user has successfully authenticated they're account, twitter redirects to the callback endpoint, with the valid user data.... essentially the auth has been successful. However, when sending the user back to the client side application a html document with the word null is presented, rather than the application.

With the following code, I expect:

  • Twitter to return to callback URL
  • Server to perform actions in authSuccess function
  • Redirect to the provided url on the client
  • routes.js to server the application shell via the catch all route
  • Client application to boot and handle the URL served

Currently, only the first two steps are successful, and the app simply displays null (with the correct url in the address bar), rather than the expected output. Changing the location of the writeHead() call to / works, and the user is authenticated as expected ().

routes.js

let users = require('../controllers/userController');

app.get('/user/auth/twitter/callback',
  passport.authenticate('twitter', {
    failWithError: true
  }),
  function(req, res) {
    console.log('[Twitter] Auth success route hit');
    users.authSuccess(req, res);
  },
  function(err, req, res, next) {
    console.log('[Twitter] Auth failure route hit');
    users.authFailure(err, req, res, next);
  }
);

app.get('*', function(req, res){
   console.log('[Route] Catch All: ' + req.path);
   res.sendFile(path.resolve(__dirname, '../../public/index.html'));
});

userController.js

authSuccess(req, res) {
  console.log('[User Controller] User',req.user);

  // Set some cookies here

  res.writeHead(302, {'Location': '/user/profile'});
  // res.redirect('/user/profile');
  res.end();
}

Any help much appreciated. If you need more code, just ask :)

Thanks

about 4 years ago · Santiago Trujillo
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!