Questions tagged [js-cookie]

A simple, lightweight JavaScript API for handling cookies (previously called jquery-cookie)

A simple, lightweight JavaScript API for handling cookies (previously )

Feature Overview

  • Crossbrowser
  • Doesn't rely on any framework
  • Supports ES modules
  • Supports AMD/CommonJS
  • RFC 6265 compliant

Documentation & Links

130 questions
3
votes
2 answers

Can't get cookies with js-cookie and react

I'm using Nextjs and trying to make multi language application. Multi langugage working properly but when I'm trying get language code with cookie like 'en', getting error. This way working; initialLang = 'en'; setDefaultTranslations({en,…
3
votes
2 answers

How to get `csrftoken` in Vue.js?

In Vue.js project, how can I get the csrftoken? I tried use js-cookie, but can not get it: import Cookies from 'js-cookie'; if (Cookies.get('csrftoken')!==undefined) { // there will skip, because the Cookies.get('csrftoken') is undefined. …
user7693832
  • 6,119
  • 19
  • 63
  • 114
3
votes
1 answer

How to use js-cookie in a TypeScript project?

I want to use the js-cookie library in my TypeScript project. First, I installed the library and the typings by running npm install js-cookie @types/js-cookie --save-dev in the directory that contains node_modules and package.json. package.json now…
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
3
votes
4 answers

Woocommerce - Cookies is not defined

Well, I'm getting JS error "Cookies is not defined", but "js.cookie.min.js" is loaded before "woocommerce.min.js". I check apache log to see if there's any error, but has none. I don't have caching plugins. I don't know how to track this error to…
lcssanches
  • 995
  • 12
  • 33
2
votes
1 answer

How can the cookie value not be the same in the dynamic route?

I implemented a program with next js , i want to use cookies on dynamic pages , the problem is that the cookie value is inherited in other pages , this happens while each page should have its own cookie. I want to have a button to set cookie and a…
2
votes
1 answer

Type error: Property 'get' does not exist on type 'typeof import("js-cookie")'

I'm unable to build the following JS react code: import Cookies from 'js-cookie'; React.useEffect(() => { interface UserInfo { name: string; verified: boolean; } const userInfo = Cookies.get('userInfo'); if (userInfo &&…
user8411456
  • 347
  • 1
  • 5
  • 18
2
votes
0 answers

get method of js-cookie return undefined

Now I'm using js-cookie to store token in cookie and I meet some problems that I can not get token by Cookies.get method, get method is defined as below: import Cookies from 'js-cookie' class CookieService { get(key: string) { return…
2
votes
1 answer

What is the difference between set cookie, res cookie and Cooki.set() (js-cookie)?

I am trying to implement an authentication system and I've run into some problems and after a lot of troubleshooting I've come to realise that I don't fully understand the difference between theese three: res.cookie(name, value,…
Kennons
  • 25
  • 7
2
votes
1 answer

Retrieving data from Cookies (js-cookie) while testing in jest

How can I test Cookies.get with jest testing I have util.js folder where I call function const fullObjectStr = Cookies.get(cookieName); So, I want to test it with jest. How can I do that? I've tried a few things from this question: How to mock…
Sveto
  • 33
  • 1
  • 3
2
votes
1 answer

Rails 6 with js-cookie library: cookie is set but not persistent

I've been trying to set up a very simple cookie just to see if the user has clicked the cookie consent banner. I'm trying to set the cookie with an expiration date in the future so the user doesn't get this message every visit. It works to set the…
Sprouter
  • 312
  • 1
  • 2
  • 10
2
votes
1 answer

React app freezing due to useEffect hook in 16.9 while working fine in 16.8

The code runs fine on React 16.8, yet freezes on >=16.9. I looked at the changes for 16.9 but all it mentioned was an additional warning when there's an infinite loop, not an actual change in behaviour, so this shouldn't be happening, yet it is.…
JH-
  • 362
  • 2
  • 12
2
votes
1 answer

Vuex with Cookie Storage loses state after Page Refresh

I'm using Vuex with cookie storage, but when I do a F5 page refresh the state is lost. I can't figure out why. I've tried toggling the "secure" option from "true" and "false", but it doesn't fix it. I'm testing on my local environment with…
user3084526
  • 35
  • 1
  • 5
2
votes
2 answers

How to solve ReferenceError: Cookies is not defined

I am setting up a modal which will hide after a user click submit the request. if ( Cookies.get("submitted") && JSON.parse(Cookies.get("submitted")) ) { $("#booking-form-modal").hide(); return true; error page
Anil Loutombam
  • 355
  • 6
  • 19
2
votes
2 answers

Display a modal after x pages views with JS Cookie?

I'm trying to display a Bootstrap modal avec 3 pages viewed on my website, and find an actualized solution of this question, with the JS-Cookie plugin. I tried this code but it's not working : $(document).ready(function () { // create cookie …
Yougchrys
  • 33
  • 5
2
votes
2 answers

How to block or remove third-party cookies

How do I delete/block third-party cookies for example Facebook or Instagram cookies? This is the code I got so far and is working for cookies on my domain. The cookie "_gid" is removed when clicked. (The "JSESSIONID" Cookie is…
nibor90
  • 93
  • 2
  • 5
1
2
3
8 9