From 47469b6764dc2c3d94007930897c9ea670102f5d Mon Sep 17 00:00:00 2001 From: Hummel009 Date: Fri, 6 Dec 2024 14:15:05 +0300 Subject: [PATCH] js cookie --- appLab3/front/package-lock.json | 10 ++++++++++ appLab3/front/package.json | 1 + appLab3/front/src/App.js | 3 +-- appLab4/front/package-lock.json | 10 ++++++++++ appLab4/front/package.json | 1 + appLab4/front/src/App.js | 3 +-- appLab5/front/package-lock.json | 10 ++++++++++ appLab5/front/package.json | 1 + appLab5/front/src/App.js | 4 +--- appLab6/front/package-lock.json | 10 ++++++++++ appLab6/front/package.json | 1 + appLab6/front/src/App.js | 3 +-- 12 files changed, 48 insertions(+), 9 deletions(-) diff --git a/appLab3/front/package-lock.json b/appLab3/front/package-lock.json index 06cadcd..b758a47 100644 --- a/appLab3/front/package-lock.json +++ b/appLab3/front/package-lock.json @@ -12,6 +12,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", @@ -12750,6 +12751,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/appLab3/front/package.json b/appLab3/front/package.json index 9f17e8e..b22e448 100644 --- a/appLab3/front/package.json +++ b/appLab3/front/package.json @@ -7,6 +7,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", diff --git a/appLab3/front/src/App.js b/appLab3/front/src/App.js index 578f063..f8b6e74 100644 --- a/appLab3/front/src/App.js +++ b/appLab3/front/src/App.js @@ -88,8 +88,7 @@ function App() { const tryUseCookieToken = async () => { try { - const tokenCookie = document.cookie.split('; ').find(row => row.startsWith('jwt=')); - const token = tokenCookie ? tokenCookie.split('=')[1] : null; + const token = Cookies.get('jwt'); await axios.post('http://localhost:2999/token', { token: token diff --git a/appLab4/front/package-lock.json b/appLab4/front/package-lock.json index 06cadcd..b758a47 100644 --- a/appLab4/front/package-lock.json +++ b/appLab4/front/package-lock.json @@ -12,6 +12,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", @@ -12750,6 +12751,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/appLab4/front/package.json b/appLab4/front/package.json index 9f17e8e..b22e448 100644 --- a/appLab4/front/package.json +++ b/appLab4/front/package.json @@ -7,6 +7,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", diff --git a/appLab4/front/src/App.js b/appLab4/front/src/App.js index 7f0ce70..643273f 100644 --- a/appLab4/front/src/App.js +++ b/appLab4/front/src/App.js @@ -135,8 +135,7 @@ function App() { const tryUseCookieToken = async () => { if (tokenWsRef.current) { - const tokenCookie = document.cookie.split('; ').find(row => row.startsWith('jwt=')); - const token = tokenCookie ? tokenCookie.split('=')[1] : null; + const token = Cookies.get('jwt'); tokenWsRef.current.send(JSON.stringify({ token: token diff --git a/appLab5/front/package-lock.json b/appLab5/front/package-lock.json index 06cadcd..b758a47 100644 --- a/appLab5/front/package-lock.json +++ b/appLab5/front/package-lock.json @@ -12,6 +12,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", @@ -12750,6 +12751,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/appLab5/front/package.json b/appLab5/front/package.json index 9f17e8e..b22e448 100644 --- a/appLab5/front/package.json +++ b/appLab5/front/package.json @@ -7,6 +7,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", diff --git a/appLab5/front/src/App.js b/appLab5/front/src/App.js index b956961..9f6051b 100644 --- a/appLab5/front/src/App.js +++ b/appLab5/front/src/App.js @@ -124,9 +124,7 @@ function App() { }; const tryUseCookieToken = async () => { - const cookies = document.cookie.split('; '); - const tokenCookie = cookies.find(row => row.startsWith('jwt=')); - const token = tokenCookie ? tokenCookie.split('=')[1] : null; + const token = Cookies.get('jwt'); const query = ` mutation { diff --git a/appLab6/front/package-lock.json b/appLab6/front/package-lock.json index 06cadcd..b758a47 100644 --- a/appLab6/front/package-lock.json +++ b/appLab6/front/package-lock.json @@ -12,6 +12,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", @@ -12750,6 +12751,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/appLab6/front/package.json b/appLab6/front/package.json index 9f17e8e..b22e448 100644 --- a/appLab6/front/package.json +++ b/appLab6/front/package.json @@ -7,6 +7,7 @@ "@testing-library/react": "^16.0.1", "@testing-library/user-event": "^14.5.2", "axios": "^1.7.7", + "js-cookie": "^3.0.5", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", diff --git a/appLab6/front/src/App.js b/appLab6/front/src/App.js index 578f063..f8b6e74 100644 --- a/appLab6/front/src/App.js +++ b/appLab6/front/src/App.js @@ -88,8 +88,7 @@ function App() { const tryUseCookieToken = async () => { try { - const tokenCookie = document.cookie.split('; ').find(row => row.startsWith('jwt=')); - const token = tokenCookie ? tokenCookie.split('=')[1] : null; + const token = Cookies.get('jwt'); await axios.post('http://localhost:2999/token', { token: token