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

94
Views
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 answers
Answer question

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 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!