Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda