From ddc694a3a17374b7842fcc1c7e935d189b2bf450 Mon Sep 17 00:00:00 2001 From: trandaison Date: Tue, 8 Oct 2024 15:45:32 +0700 Subject: [PATCH] feat: Switch to cookie-es --- package.json | 5 ++-- pnpm-lock.yaml | 41 ++++++++++------------------ src/runtime/services/AuthStorage.ts | 2 +- src/runtime/utils/UniversalCookie.ts | 10 +++---- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index 6921a6a..dd0899f 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,9 @@ "@nuxt/kit": "^3.8.2", "@nuxtjs/i18n": "^8.2.0", "@pinia/nuxt": "^0.5.1", + "cookie-es": "^1.2.2", "defu": "^6.1.3", - "jwt-decode": "^3.1.2", + "jwt-decode": "^4.0.0", "lodash-es": "^4.17.21", "ofetch": "^1.3.3", "pathe": "^1.1.1", @@ -51,11 +52,9 @@ "@nuxt/module-builder": "^0.8.4", "@nuxt/schema": "^3.8.2", "@nuxt/test-utils": "^3.12.0", - "@types/cookie": "^0.6.0", "@types/lodash-es": "^4.17.12", "@types/node": "^20.10.3", "changelogen": "^0.5.5", - "cookie": "^0.6.0", "eslint": "^8.55.0", "nuxt": "^3.13.2", "vitepress": "^1.2.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8222e34..b7286a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,12 +20,15 @@ importers: '@pinia/nuxt': specifier: ^0.5.1 version: 0.5.5(magicast@0.3.5)(rollup@4.24.0)(typescript@5.6.2)(vue@3.5.10(typescript@5.6.2)) + cookie-es: + specifier: ^1.2.2 + version: 1.2.2 defu: specifier: ^6.1.3 version: 6.1.4 jwt-decode: - specifier: ^3.1.2 - version: 3.1.2 + specifier: ^4.0.0 + version: 4.0.0 lodash-es: specifier: ^4.17.21 version: 4.17.21 @@ -57,9 +60,6 @@ importers: '@nuxt/test-utils': specifier: ^3.12.0 version: 3.14.2(h3@1.12.0)(magicast@0.3.5)(nitropack@2.9.7(magicast@0.3.5))(rollup@4.24.0)(vite@5.4.8(@types/node@20.16.10)(sass@1.79.4)(terser@5.34.1))(vitest@1.6.0(@types/node@20.16.10)(sass@1.79.4)(terser@5.34.1))(vue-router@4.4.5(vue@3.5.10(typescript@5.6.2)))(vue@3.5.10(typescript@5.6.2)) - '@types/cookie': - specifier: ^0.6.0 - version: 0.6.0 '@types/lodash-es': specifier: ^4.17.12 version: 4.17.12 @@ -69,9 +69,6 @@ importers: changelogen: specifier: ^0.5.5 version: 0.5.7(magicast@0.3.5) - cookie: - specifier: ^0.6.0 - version: 0.6.0 eslint: specifier: ^8.55.0 version: 8.57.1 @@ -80,7 +77,7 @@ importers: version: 3.13.2(@parcel/watcher@2.4.1)(@types/node@20.16.10)(eslint@8.57.1)(ioredis@5.4.1)(magicast@0.3.5)(optionator@0.9.4)(rollup@4.24.0)(sass@1.79.4)(terser@5.34.1)(typescript@5.6.2)(vite@5.4.8(@types/node@20.16.10)(sass@1.79.4)(terser@5.34.1)) vitepress: specifier: ^1.2.3 - version: 1.3.4(@algolia/client-search@4.24.0)(@types/node@20.16.10)(jwt-decode@3.1.2)(postcss@8.4.47)(sass@1.79.4)(search-insights@2.17.2)(terser@5.34.1)(typescript@5.6.2) + version: 1.3.4(@algolia/client-search@4.24.0)(@types/node@20.16.10)(jwt-decode@4.0.0)(postcss@8.4.47)(sass@1.79.4)(search-insights@2.17.2)(terser@5.34.1)(typescript@5.6.2) vitest: specifier: ^1.6.0 version: 1.6.0(@types/node@20.16.10)(sass@1.79.4)(terser@5.34.1) @@ -1444,9 +1441,6 @@ packages: resolution: {integrity: sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==} engines: {node: '>=10.13.0'} - '@types/cookie@0.6.0': - resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==} - '@types/estree@1.0.6': resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} @@ -2065,10 +2059,6 @@ packages: cookie-es@1.2.2: resolution: {integrity: sha512-+W7VmiVINB+ywl1HGXJXmrqkOhpKrIiVZV6tQuV54ZyQC7MMuBt81Vc336GMLoHBq5hV/F9eXgt5Mnx0Rha5Fg==} - cookie@0.6.0: - resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==} - engines: {node: '>= 0.6'} - copy-anything@3.0.5: resolution: {integrity: sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==} engines: {node: '>=12.13'} @@ -2881,8 +2871,9 @@ packages: jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} - jwt-decode@3.1.2: - resolution: {integrity: sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==} + jwt-decode@4.0.0: + resolution: {integrity: sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==} + engines: {node: '>=18'} keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} @@ -5915,8 +5906,6 @@ snapshots: '@trysound/sax@0.2.0': {} - '@types/cookie@0.6.0': {} - '@types/estree@1.0.6': {} '@types/hast@3.0.4': @@ -6287,14 +6276,14 @@ snapshots: - '@vue/composition-api' - vue - '@vueuse/integrations@11.1.0(focus-trap@7.6.0)(jwt-decode@3.1.2)(vue@3.5.10(typescript@5.6.2))': + '@vueuse/integrations@11.1.0(focus-trap@7.6.0)(jwt-decode@4.0.0)(vue@3.5.10(typescript@5.6.2))': dependencies: '@vueuse/core': 11.1.0(vue@3.5.10(typescript@5.6.2)) '@vueuse/shared': 11.1.0(vue@3.5.10(typescript@5.6.2)) vue-demi: 0.14.10(vue@3.5.10(typescript@5.6.2)) optionalDependencies: focus-trap: 7.6.0 - jwt-decode: 3.1.2 + jwt-decode: 4.0.0 transitivePeerDependencies: - '@vue/composition-api' - vue @@ -6673,8 +6662,6 @@ snapshots: cookie-es@1.2.2: {} - cookie@0.6.0: {} - copy-anything@3.0.5: dependencies: is-what: 4.1.16 @@ -7586,7 +7573,7 @@ snapshots: optionalDependencies: graceful-fs: 4.2.11 - jwt-decode@3.1.2: {} + jwt-decode@4.0.0: {} keyv@4.5.4: dependencies: @@ -9203,7 +9190,7 @@ snapshots: sass: 1.79.4 terser: 5.34.1 - vitepress@1.3.4(@algolia/client-search@4.24.0)(@types/node@20.16.10)(jwt-decode@3.1.2)(postcss@8.4.47)(sass@1.79.4)(search-insights@2.17.2)(terser@5.34.1)(typescript@5.6.2): + vitepress@1.3.4(@algolia/client-search@4.24.0)(@types/node@20.16.10)(jwt-decode@4.0.0)(postcss@8.4.47)(sass@1.79.4)(search-insights@2.17.2)(terser@5.34.1)(typescript@5.6.2): dependencies: '@docsearch/css': 3.6.2 '@docsearch/js': 3.6.2(@algolia/client-search@4.24.0)(search-insights@2.17.2) @@ -9214,7 +9201,7 @@ snapshots: '@vue/devtools-api': 7.4.6 '@vue/shared': 3.5.10 '@vueuse/core': 11.1.0(vue@3.5.10(typescript@5.6.2)) - '@vueuse/integrations': 11.1.0(focus-trap@7.6.0)(jwt-decode@3.1.2)(vue@3.5.10(typescript@5.6.2)) + '@vueuse/integrations': 11.1.0(focus-trap@7.6.0)(jwt-decode@4.0.0)(vue@3.5.10(typescript@5.6.2)) focus-trap: 7.6.0 mark.js: 8.11.1 minisearch: 7.1.0 diff --git a/src/runtime/services/AuthStorage.ts b/src/runtime/services/AuthStorage.ts index 33bdc3c..90332c8 100644 --- a/src/runtime/services/AuthStorage.ts +++ b/src/runtime/services/AuthStorage.ts @@ -1,4 +1,4 @@ -import jwtDecode from "jwt-decode"; +import { jwtDecode } from "jwt-decode"; import { storeToRefs } from "pinia"; import type { AuthConfig, User, AuthTokens } from "../../types"; import { useAuthStore } from "../store/auth"; diff --git a/src/runtime/utils/UniversalCookie.ts b/src/runtime/utils/UniversalCookie.ts index a6a1544..59b62b0 100644 --- a/src/runtime/utils/UniversalCookie.ts +++ b/src/runtime/utils/UniversalCookie.ts @@ -1,5 +1,5 @@ import { useRequestEvent } from '#imports'; -import cookie, { type CookieSerializeOptions } from 'cookie'; +import { parse, serialize, type CookieSerializeOptions } from 'cookie-es'; import { setCookie as _setCookie, deleteCookie } from 'h3'; export default class UniversalCookie { @@ -14,7 +14,7 @@ export default class UniversalCookie { constructor() { this.requestEvent = useRequestEvent(); if (import.meta.server && this.requestEvent) { - this.cache = cookie.parse(this.requestEvent?.headers?.get('cookie') || ''); + this.cache = parse(this.requestEvent?.headers?.get('cookie') || ''); } } @@ -23,7 +23,7 @@ export default class UniversalCookie { return this.requestEvent ? this.cache![name] : undefined; } - return cookie.parse(document.cookie)[name]; + return parse(document.cookie)[name]; } setCookie(name: string, value: string | null, options: CookieSerializeOptions = {}) { @@ -37,7 +37,7 @@ export default class UniversalCookie { _setCookie(this.requestEvent, name, value, options); this.cache![name] = value; } else { - document.cookie = cookie.serialize(name, value, options); + document.cookie = serialize(name, value, options); } } @@ -47,7 +47,7 @@ export default class UniversalCookie { deleteCookie(this.requestEvent, name, options); delete this.cache![name]; } else { - document.cookie = cookie.serialize(name, '', { ...options, maxAge: -1 }); + document.cookie = serialize(name, '', { ...options, maxAge: -1 }); } } }