Cookie gets removed when switching between tabs or browser closed

26 Views Asked by At

I am using js-cookie package to set cookies. The problem is that when I close the browser or switch to another tab and browse for sometimes and then come back to my website, the cookie gets removed even though I set a expiration time in the cookie according to the documentation. How can I persist cookie for my expected time period?

import Cookies from "js-cookie";

function App() {

 const setCookie = () => {
   Cookies.set("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", {
     expires: 7,
   });
 };

 return (
   <button onClick={setCookie}>
      Set Cookie
   </button>
 );
}

export default App;
0

There are 0 best solutions below