简体   繁体   中英

Passing header along with res redirect without using query strings

I want to set a header after redirecting to a particular route.

app.post('/signup', (req,res) => {
    var user = new User(req.body);
    req.method = 'get';
// console.log(req.body);
    user.save().then((doc) => {
        console.log("hi");
        return user.generateAuthToken().then((token) => {
            res.header('x-auth',token);
            res.redirect('home.hbs');
        });
    })
});

I want to pass the token as a header without the use of query strings. How would it be possible?

In HTTP, a redirect response provides a URL for the user agent to request. It doesn't specify the rest of the request.

You can set a cookie though, if the redirect destination is in the same domain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM