Its possible to set a domain string as default setting?
Actual for each set/get
Cookies.set('name', 'value', { expires: 1, domain: '.example.com' }));
Maybe better and shorter
// Set default values
Cookies.settings({ expires: 1, domain: '.example.com' });
Cookies.set('name', 'value')); // => expires is 1 day; domain is '.example.com'
Cookies.set('name', 'value', { expires: 3 })); // => domain is '.example.com'
In most cases I think the domain is always same.
From the readme:
Cookie attributes defaults can be set globally by setting properties of the Cookies.defaults object
https://github.com/js-cookie/js-cookie/blob/master/README.md
(We might have to make this sentence more prominent.)
Oh, thanks! It would help much to include a simple code example. :)
Agreed, this could use an example.
My code is:
Cookies.defaults({
secure: true,
sameSite: 'lax'
});
but it gives:
TypeError: Cookies.defaults is not a function
How can I solve?
@Fabio-Zeus-Soft
With v2: Cookies.defaults = { ... }
Configure Default Cookie Attributes
Cookies.defaults = {
path: "/",
domain: ".example.com",
secure: false,
expires: 365,
};
Create a New Cookie with Default Values
Cookies.set('name', 'value');
Set Cookie and Override Default(s)
Cookies.set('name', 'value', { expires: 7, path: '' });
Most helpful comment
Oh, thanks! It would help much to include a simple code example. :)