title: How to redirect to a specific page after successful login using express and vue js?
body: <p>I am developing a simple CRUD application using MVEN stack. I have also added authentication feature using passportJs. But I am getting error in redirecting. I guess there is some mistake with the routing that I have used. I have shared my code below.</p>
  
  <p><strong>authRoutes.js</strong></p>
  
  <pre><code>var express = require('express');
  var authRoutes = express.Router();
  var passport = require('passport'),
      LocalStrategy = require('passport-local').Strategy;
  
  app = express();
  // Require Item model in our routes module
  var User = require('../models/User');
  var Item = require('../models/Item');
  
  
  passport.use(new LocalStrategy(
    function(username, password, done) {
      User.findOne({ username: username }, function(err, user) {
        if (err) { return done(err); }
        if (!user) {
          return done(null, false, { message: 'Incorrect username.' });
        }
        if (!user.validPassword(password)) {
          return done(null, false, { message: 'Incorrect password.' });
        }
        return done(null, user);
      });
    }
  ));
  
  // Serialize user in session
  passport.serializeUser((user, done) =&gt; {
    done(null, user.username);
  });
  
  passport.deserializeUser((username, done) =&gt; {
    const user = getUser(username);
    delete user.password;
    done(null, user);
  });
  
  authRoutes.route('/register').post(function (req, res) {
  var user = new User(req.body);
        user.save()
      .then(user =&gt; {
      res.status(200).json({'user': 'user added successfully'});
      })
      .catch(err =&gt; {
      res.status(400).send("unable to save to database");
      });
  });
  
  authRoutes.route('/login').post( function(req, res){
    passport.authenticate('local',{
      failureRedirect: '/',
      successRedirect: '/display',
      failureFlash: true,
    });
  });
  
  
  
  authRoutes.route('/display').get(function (req, res) {
    Item.find(function (err, items){
      if(err){
        console.log(err);
      }
      else {
        res.json(items);
      }
    });
  });
  
  
  module.exports = authRoutes
  </code></pre>
  
  <p>login.vue</p>
  
  <pre><code>&lt;template&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-6"&gt;
              &lt;h1&gt;Register User&lt;/h1&gt;
              &lt;form v-on:submit.prevent="registerUser"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for=""&gt;Email:&lt;/label&gt;
                  &lt;input type="text" v-model="user.email"&gt;
              &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for=""&gt;Password:&lt;/label&gt;
                  &lt;input type="password" v-model="user.password"&gt;
              &lt;/div&gt;
              &lt;button&gt;Register&lt;/button&gt;
              &lt;/form&gt;
              &lt;p v-if="isRegistered"&gt;Thanks for registering.&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="col-md-6"&gt;
              &lt;h1&gt;Login&lt;/h1&gt;
              &lt;form v-on:submit.prevent="loginUser"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for=""&gt;Email:&lt;/label&gt;
                  &lt;input type="text" v-model="loginData.email"&gt;
              &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label for=""&gt;Password:&lt;/label&gt;
                  &lt;input type="password" v-model="loginData.password"&gt;
              &lt;/div&gt;
              &lt;button&gt;Login&lt;/button&gt;
              &lt;/form&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/template&gt;
  &lt;script&gt;
      export default{
          data (){
              return{
                  user:{},
                  isRegistered: false,
                  loginData:{}
              };
          },
          methods: {
              registerUser(){
                  let uri = 'http://localhost:4000/auths/register';
                this.axios.post(uri, this.user).then((response) =&gt; {
                  this.isRegistered = true;
                  this.user = {};
                })
                .catch((err) =&gt; console.log(err));
              },
  
              loginUser(){
                  let uri = 'http://localhost:4000/auths/login';
                  debugger;
                  this.axios.post(uri, this.loginData).then((response) =&gt; {
                      this.$router.push({name:'DisplayItem'});
                  })
                  .catch((err) =&gt; {
                      console.log(err);
  
                      this.$router.push({name:'Register'});
                  });
              }
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>The issue is, it is not redirecting to /display when username and password are correct. What am I doing wrong.</p>