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
2
votes
1 answer

how do i set expire time to hours or minutes in Cookie and Vue-persist? Vuex

const vuexCookie = new VuexPersist({ restoreState: (key, storage) => Cookies.getJSON(key), saveState: (key, state, storage) => Cookies.set(key, state, { expires: 3 }), modules: ['user'] // only save user module }) How do i set the…
Dike Jude
  • 199
  • 3
  • 9
2
votes
2 answers

JS Cookie Disable in console

I have setup my site to save cookies using the js-cookie plugin. However when I am in in the developer console I am able to set the cookie by using Cookies.set('name', 'value') I want to disable this so users are unable to set/change the cookie. Is…
Lee Proctor
  • 257
  • 1
  • 3
  • 11
2
votes
1 answer

js-cookie enzyme testing fails on testing cookie.set function

I am trying to unit test js-cookie My code is like this import Cookie from 'js-cookie' onChange (e) { Cookie.set('locale', e.target.value) window.location.reload() } and for unit testing I am doing this describe('LocaleDropDown', () =>…
keerti
  • 245
  • 5
  • 19
1
vote
0 answers

Cookies are not set in Safari until page refresh

If I go to the JS console in Safari and write document.cookie = 'cookie1=test; expires=Sun, 1 Jan 2023 00:00:00 UTC; path=/' the cookie won't be visible under the Storage tab until I refresh the page. This behaviour seems to be Safari specific and…
TheGabornator
  • 523
  • 1
  • 7
  • 20
1
vote
1 answer

How to use JS-Cookie in an if statement

I'm looking to use cookies to disable a button after one press using Js-Cookie for a quiz start_btn.onclick = ()=>{ info_box.classList.add("activeInfo"); } I'm not sure whether I should reference the button or edit its function? so say I was…
1
vote
1 answer

set js-cookie value to firebase token

Is it ok to set the value of a cookie to a token? I'm using js-cookie, Firebase auth/firestore and Next.js and I have my cookie set like this inside of my handleUser function: const handleUser = async (rawUser) => { if (rawUser) { const…
1
vote
0 answers

How to use useContext and Cookies together correctly from server?

For context, I am able to use useContext and js-cookies to render/save the changes in client-side, but since I am not able to access the cookies from the server-side loading in the stateContext.js, the initial values saved to the state are always…
Airix
  • 11
  • 2
1
vote
1 answer

Set Cookie in React app works in localhost but not in production

I am trying to set a cookie on the client side in my react web app. I am using CRA deployed to Firebase. Tried both js-cookie and react-cookie - in both cases I see that the set cookie code is running correctly. When developing in localhost…
amiregelz
  • 1,833
  • 7
  • 25
  • 46
1
vote
1 answer

Upgrading an angular 13 app with js-cookie stops running jest unit tests successfully

I have an angular app with version 13 which is using the external dependency js-cookie to set and get some cookies in the browser. As a test environment I am using jest with jest-preset-angular. See all dependencies of the package.json below. My…
JV3
  • 872
  • 2
  • 9
  • 21
1
vote
1 answer

TypeError: Cannot read properties of undefined (reading 'set')

While I am trying to develop mern ec site. This error has occurred on the sign in page. what I have tried 1 Cookies->Cookie, set->Set 2 res.refresh_token->'res.refresh_token' 3 downgrade js-cookies version from 3 to…
Kanta Yamada
  • 45
  • 1
  • 6
1
vote
2 answers

Is there a reason why this function only works once?

I am using JS-Cookie to make a simple clicker game. When I call the function, it works once, but then I have to refresh for the function to work again. I have tried adding a console.log after it to help debug it, and the log shows up, but the…
DevOffline
  • 77
  • 7
1
vote
0 answers

using js-cookies, how to easily set an object as a cookie?

import Cookies from "js-cookies"; Cookies.setItem("email", "kiwi@yahoo.com"); Cookies.setItem("password", "123456"); But, I want to do something like this: const user = { email: "kiwi@yahoo.com", password: "123456" } Cookies.setItem(user);
1
vote
0 answers

Javascript Cookies being reset after page reload

Good day. I've been using js-cookie to set cookies in my application, they are set in the exact same way however one of them turns into undefined whenever i use window.location or reload the page. I set 2 cookies, one for a token and one for for the…
1
vote
1 answer

How to pass CSRF token in POST data to Django?

I am developing an application with Django backend and Next.js frontend. I am trying to POST data from the frontend to the backend using the fetch API. I am having problems passing a valid CSRF token in my POST data to Django. I am trying to do it…
fredperk
  • 737
  • 1
  • 9
  • 22
1
vote
2 answers

js-cookie with sameSite None & secure

how do i use js-cookie with sameSite set to none & secure? is this something like this? Cookies.set("name", "value", {SameSite : "None; secure" });
1 2
3
8 9