Browse Source

cookie 改为 sessionStorage

黄琪勇 2 months ago
parent
commit
6e2b065e99
3 changed files with 3 additions and 35 deletions
  1. 0 27
      package-lock.json
  2. 0 2
      package.json
  3. 3 6
      src/libs/auth.ts

+ 0 - 27
package-lock.json

@@ -21,7 +21,6 @@
         "hfmath": "^0.0.2",
         "html-to-image": "^1.11.11",
         "html2canvas": "^1.4.1",
-        "js-cookie": "^3.0.5",
         "lodash": "^4.17.21",
         "mitt": "^3.0.1",
         "nanoid": "^5.0.7",
@@ -50,7 +49,6 @@
         "@rushstack/eslint-patch": "^1.3.3",
         "@tsconfig/node18": "^18.2.2",
         "@types/crypto-js": "^4.2.1",
-        "@types/js-cookie": "^3.0.3",
         "@types/lodash": "^4.14.202",
         "@types/node": "^18.19.3",
         "@types/svg-arc-to-cubic-bezier": "^3.2.2",
@@ -1171,12 +1169,6 @@
       "resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.5.tgz",
       "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
     },
-    "node_modules/@types/js-cookie": {
-      "version": "3.0.6",
-      "resolved": "https://registry.npmmirror.com/@types/js-cookie/-/js-cookie-3.0.6.tgz",
-      "integrity": "sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==",
-      "dev": true
-    },
     "node_modules/@types/json-schema": {
       "version": "7.0.15",
       "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
@@ -3230,14 +3222,6 @@
         "url": "https://github.com/chalk/supports-color?sponsor=1"
       }
     },
-    "node_modules/js-cookie": {
-      "version": "3.0.5",
-      "resolved": "https://registry.npmmirror.com/js-cookie/-/js-cookie-3.0.5.tgz",
-      "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
-      "engines": {
-        "node": ">=14"
-      }
-    },
     "node_modules/js-tokens": {
       "version": "4.0.0",
       "resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -5642,12 +5626,6 @@
       "resolved": "https://registry.npmmirror.com/@types/estree/-/estree-1.0.5.tgz",
       "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
     },
-    "@types/js-cookie": {
-      "version": "3.0.6",
-      "resolved": "https://registry.npmmirror.com/@types/js-cookie/-/js-cookie-3.0.6.tgz",
-      "integrity": "sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==",
-      "dev": true
-    },
     "@types/json-schema": {
       "version": "7.0.15",
       "resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
@@ -7247,11 +7225,6 @@
         }
       }
     },
-    "js-cookie": {
-      "version": "3.0.5",
-      "resolved": "https://registry.npmmirror.com/js-cookie/-/js-cookie-3.0.5.tgz",
-      "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw=="
-    },
     "js-tokens": {
       "version": "4.0.0",
       "resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz",

+ 0 - 2
package.json

@@ -26,7 +26,6 @@
     "hfmath": "^0.0.2",
     "html-to-image": "^1.11.11",
     "html2canvas": "^1.4.1",
-    "js-cookie": "^3.0.5",
     "lodash": "^4.17.21",
     "mitt": "^3.0.1",
     "nanoid": "^5.0.7",
@@ -55,7 +54,6 @@
     "@rushstack/eslint-patch": "^1.3.3",
     "@tsconfig/node18": "^18.2.2",
     "@types/crypto-js": "^4.2.1",
-    "@types/js-cookie": "^3.0.3",
     "@types/lodash": "^4.14.202",
     "@types/node": "^18.19.3",
     "@types/svg-arc-to-cubic-bezier": "^3.2.2",

+ 3 - 6
src/libs/auth.ts

@@ -1,5 +1,3 @@
-import Cookies from "js-cookie"
-
 /* code */
 // eslint-disable-next-line prefer-const
 export let CODE401 = 5000 // 没有权限
@@ -10,19 +8,18 @@ export function setCODE401(code: number) {
 
 /** cookie */
 const TokenKey = "ppt-Token"
-const expiresDate = 7
 
 export let TokenInvalidFlag = true // 令牌是否有效
 export function getToken() {
-  return Cookies.get(TokenKey)
+  return sessionStorage.getItem(TokenKey)
 }
 
 export function setToken(token: string) {
   TokenInvalidFlag = true
-  return Cookies.set(TokenKey, token, { expires: expiresDate })
+  return sessionStorage.setItem(TokenKey, token)
 }
 
 export function removeToken() {
   TokenInvalidFlag = false
-  return Cookies.remove(TokenKey)
+  sessionStorage.removeItem(TokenKey)
 }