In this app, we no longer use sessions to "remember" the authenticated data. Instead, we will use the js-cookie Node.js module to create cookies to store the data from the remote server.
It is very easy to use this Node.js module to create a cookie that presents across the entire site; for example:
- Use the following format to set a cookie:
Cookies.set(<name>, <value>)
Here's the code for if you want to create a cookie that expires 30 days from now:
Cookies.set(<name>, <value>, { expires: 30 })
- Use the following format to read the cookie:
Cookies.get(<name>)
You can see how easy it is using this Node.js module – all you need is the set and get methods to set and retrieve your cookies on the client side. So, let's refactor the code in our store in the following steps:
- Use the if ternary condition to import the js-cookie Node.js module when our Nuxt app is processed on the client...