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

153
Views
Change "Unauthorized" response of Node.js Passport

I'm using passport for user authentication and it is working fine, but i wan't to change the message 'Unauthorized' when the user login or password is wrong.

Here is the code for the user authentication:

app.get('/login', function(req, res){
  res.render('login');
})

app.post('/login', function(req, res){
  const user = new User({
    username: req.body.username,
    password: req.body.password
  });

  req.login(user, function(err){
    if(err){
      res.send('Erro')
    } else{
      passport.authenticate('local')(req, res, function(){
        if(user){
          res.send('Positive')
        } else{
          res.send('Negative')
        }
      })
    }
  })

});

It returns 'positive' if the user type the correct login and password, but if the login and password is wrong, it returns 'Unauthorized' instead of 'negative'

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!