DEV Community

Discussion on: How to secure JWT token in React?

Collapse
 
tushark1 profile image
Tushar Khubani

Hello, I assume you are using tokens as it's a stateless app, so you might like to give js-cookie a try, seems to be a better solution than using local storage.
You can use it as follows

import Cookie from "js-cookie"

const token =  Cookie.get("token") ? Cookie.get("token") : null;

//to set a cookie
Cookie.set("token", token);

//refer the js-cookie documentation for more options