首页 > 解决方案 > How to send post data on success redirect with passport?

问题描述

I am trying to post data through my login form. I am using passport to authenticate the users credentials. Typically to post data through a form I use:

app.post('/login_mrkt', (req,res) => {
  console.log(req) //Contains post data from form
}

However as I want to authenticate the user I use the below code:

app.post('/login_mrkt', checkNotAuthenticated, passport.authenticate('local', {
    successRedirect: '/dash',
    failureRedirect: '/login',
    failureFlash: true
}))

When the login is successful it redirects my user to /dash get. However this does not contain the post data from the form:

app.get('/dash', checkAuthenticated, (req,res) => {
    console.log(req) //This does not contain post data, but I want it to
})

How can I make it so I can retrieve the post data from my fomr in the /dash get?

Edit

Here is my checkAuthenticated method as requested:

function checkAuthenticated(req, res, next) {
    if (req.isAuthenticated()) {
        return next()//can think of next() as go to the next function in the request call back function
    }
    res.redirect('/login')
}

标签: javascriptnode.jsexpresspassport.js

解决方案


推荐阅读