Setcookie Header Not Stored
I'm currently making a web app with node/express.js for the API and Vue.js for the front-end. For the authentication, I set a JWT and send the value via a cookie (HttpOnly). The 'S
Solution 1:
FINALLY, after some head bangs on my computer and researches on forums, I found the issue.
I ignored credentials on client request, thinking it was not important for authentication, but it was a huge mistake.
In fact credentials include cookies, so if you don't set credentials to 'true' when you make your request to your server/API, all returned cookies will be ignored. you have to authorize credentials both on your server and client.
so the final code was to add this option variable to my POST request : (with Vue.js)
//Request options (CORS)var options = {
headers: {
},
credentials: true
};
//Make your HTTP request:this.$http.post(<url>, payload, options).then((response) => {
//success
}, (response) => {
//error
});
Solution 2:
I have this problem for almost a week as well and figured out that setting credential to true should do the trick. If you are using Vue use an interceptor so that you don't need to call it per request
Vue.http.interceptors.push((request, next) => {
request.credentials = true;
next();
});
Post a Comment for "Setcookie Header Not Stored"