Skip to content

Commit 1f8c7a3

Browse files
committed
fix: Use cookie-es to parse cookies
This makes the parser less fragile
1 parent ba6fb6d commit 1f8c7a3

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@rollup/plugin-graphql": "^2.0.5",
4545
"@vue/apollo-composable": "^4.2.2",
4646
"@vue/apollo-option": "^4.2.2",
47+
"cookie-es": "^2.0.0",
4748
"defu": "^6.1.4",
4849
"destr": "^2.0.5",
4950
"graphql": "^16.12.0",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { destr } from 'destr'
2+
import { parse as parseCookie } from 'cookie-es'
23
import { onError } from '@apollo/client/link/error'
34
import { getMainDefinition } from '@apollo/client/utilities'
45
import { createApolloProvider } from '@vue/apollo-option'
@@ -34,7 +35,8 @@ export default defineNuxtPlugin((nuxtApp) => {
3435
token.value = t
3536
}
3637
} else if (requestCookies?.cookie) {
37-
const t = requestCookies.cookie.split(';').find(c => c.trim().startsWith(`${clientConfig.tokenName}=`))?.split('=')?.[1]
38+
const cookies = parseCookie(requestCookies.cookie)
39+
const t = cookies[clientConfig.tokenName!]
3840
if (t) {
3941
token.value = t
4042
}

0 commit comments

Comments
 (0)