-1

Currently the browser automatically deleting cookies on closing. But I want to keep the cookies until logout. How can I do that in nuxt ?

Midhun Babu
  • 119
  • 1
  • 10

1 Answers1

0

There are 2 cases:

  1. The cookie is set by the remote server - Vue or Nuxt have no control over this cookie (assuming it is marked as HttpOnly). If the cookie is a "session cookie" - it will expire when you close the browser's tab (which obviously also happens when you close the whole browser). If it is not a "session cookie" - it will have an expiration timestamp and the browser will not destroy it until (a) you close the whole browser or (b) the cookie expires (whichever happens first). Such a non-session cookie will survive the closing of the browser's tab.

  2. The cookie is created locally by JavaScript in the browser - you have full control over the cookie so you can set whatever expiration timestamp you want (either in the future or in the past) and the same rule applies (the cookie will expire either on its own or when you close the browser - but it will not expire if you close the tab)

IVO GELOV
  • 13,496
  • 1
  • 17
  • 26
  • In nuxt config there's an option to set cookie and it's expiry – Midhun Babu Nov 03 '22 at 10:03
  • @MidhunBabu According to the [official documentation](https://nuxtjs.org/docs/directory-structure/nuxt-config) there is nothing related to cookies. Which option is this? – IVO GELOV Nov 03 '22 at 14:20