Good day guys,
I'm working on a project that has Web API (RestAPI) and SPA(Single Page Application) solutions.
Based on the video that I was following on Udemy, he stored the jwt token in the localstorage but late I found out the storing in localstorage is a bit risky since the attacker can copy the actual token and make a request in the future.
I've read some blogs that storing token in the cookie is fine since you can set the cookie as httpOnly and secure. But the problem is, I don't know how to implement it.
Here's my sample code when the user has a valid login:
axios.post('api/login/', this.account).then(response=>{
if(response){
localStorage.setItem('token', response.data.token); // will successfully save to localstorage
// navigation here
}
}).catch(error=> console.log(error); );
How can I store this in cookie with secure settings?