'What's the default cookie expiration time in the react plugin universal-cookies?
I recently added universal-cookie (v4.0.4) to my react app to store whether the user has already closed the GDPR banner or not (so that it won't show it on others pages of the website) and now my client is asking me what's the expiration time for this cookie.
I've used it like this:
import Cookies from 'universal-cookie';
Cookies cookie = new Cookies();
[...]
// Constructor of my GDPR banner component
constructor() {
super();
if (cookies.get('isOpenGdprBanner') === undefined) {
cookies.set('isOpenGdprBanner', true);
}
const isOpenCookie = cookies.get('isOpenGdprBanner') === 'true'
this.state = {
isOpen: isOpenCookie
}
}
[...]
// Event when closing the banner
onGdprBannerClose = () => {
this.setState({ isOpen: false });
cookies.set('isOpenGdprBanner', false);
}
Since I didn't use the optional parameters in cookie.set(), what's the default expiration time assuming the user does not remove cookies and does not close the browser ?
Solution 1:[1]
Assuming the user does not remove the cookies and does not close the browser (as stated in the question), the cookies will never expire by default.
(You can set a maxAge to make the cookies expire earlier or even later, so they can persist after the client shuts down)
If unspecified, the cookie becomes a session cookie. A session finishes when the client shuts down, after which the session cookie is removed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gilad Pomer |
