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

99
Visualizações
Why don't I hit the campgrounds/edit page

Here is a get route and I have stored the previous link where it was redirected from in the req.session object under returnTo. After redirecting it hits the /login and we can see the object in the console.

router.get('/login', (req, res) => {
    console.log('get in user route..', req.session)
    res.render('users/login')
})
req.session :

The req.session object

router.post('/login', passport.authenticate('local', { failureFlash: true, failureRedirect: '/login' }), (req, res) => {
    req.flash('success', 'Welcome back!')
    const redirectUrl = req.session.returnTo || '/campgrounds'
    res.redirect(redirectUrl)
})

But after submitting the login details it always goes to the /campgrounds route.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I have found answer after referring to the new passport.js version. In the newer version the session id is updated. So I no longer have access to it. So, what I did is I declared a variable

let ran = ''

and stored res.locals.returnTo in ran variable.

res.locals.returnTo = req.session.returnTo
    ran = req.session.returnTo
    res.render('users/login')

So, we have access to the retrun to url even if the seesion id is updated.

about 4 years ago · Santiago Trujillo Relatório
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