I’m trying to make it so that some pages only render whenever an user is logged in. However, I can’t seem to find any documentation on how to retrieve cookies using vue.js. My project is being made with the mevn stack. And I saved the user cookie with:
res.cookie('token', token, {
maxAge: 24 * 60 * 60 * 1000,
httpOnly: true
});
The problem I’m facing now is retrieving this cookie, so that I can verify wether the user is logged in. I can’t find anything on how to do this, so I’m asking it here.
/pages/crash.vue
data() {
return {
foo: false,
};
},
mounted() {
// Get cookie
// If cookie is valid
// Set this.foo to true
if (this.foo) {
...
} else {
window.location.href = '/login'
}
},