Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda