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

144
Views
How to get passport.js to return the target url

I have a node project that uses express and passport. Right now, I have it set up to redirect the user to the login page if they are not signed in. So if the user tries to go to /finance, but they are not logged in, then it would take them to /login. But when they log in, I want it to take them to the /finance page or whichever page they originally tried to get to. Right now, it is just taking them to home when they login.

isAuthenticated.js

module.exports = ({user, url}, res, next) => {
    if (user != null) {
        next()
    } else {
        res.redirect('/login') // <-- This needs to pass the target url to POST /login in html-routes.js
    }
}

html-routes.js

app.post('/login', passport.authenticate('local', {
    successRedirect: '/', // <-- This needs to take me to the target url.
    failureRedirect: '/login',
    failureFlash: true
}))
about 4 years ago · Juan Pablo Isaza
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!