问题
I've got big problem with my login system in NodeJS. I created login site, when i'm logging in. When i check if login and password is correct i make jwt token. Then i would like to pass it into header and redirect to my user page by get method. I searched a lot of sites and I' cant solve this problem.
This is what I try to do:
const token = jwt.sign({_id: id}, process.env.TOKEN);
res.header('auth-token', token);
res.redirect('/admin/admin_panel');
I would like to this work like Postman. I set content type and my auth token to header and redirect to my route for authenticate token to get site.
回答1:
When you redirect, you're telling the client to issue a request to the redirected URL, and that URL is no the one setting the header.
If your client does not follow redirects, you will see the header set correctly for the initial request, as well as a Location
header with /admin/admin_panel
You can do one of the following if you want token
available in the new request:
- Use cookies
- Pass the token in the URL using querystring:
/admin/admin_panel?token={token}
- Other type of session
来源:https://stackoverflow.com/questions/59241078/cant-pass-header-with-token-for-redirect-nodejs