Skip to content

Commit def17ef

Browse files
committed
fix: Also use useCookie to obtain cookie during SSR
Previously, this was only used on the client, while SSR used a more "fragile" custom implementation. This makes both client-side and server-side rendering use Nuxt's built-in method.
1 parent 0194010 commit def17ef

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

src/runtime/plugin.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,9 @@ export default defineNuxtPlugin((nuxtApp) => {
2828

2929
if (!token.value) {
3030
if (clientConfig.tokenStorage === 'cookie') {
31-
if (import.meta.client) {
32-
const t = useCookie(clientConfig.tokenName!).value
33-
if (t) {
34-
token.value = t
35-
}
36-
} else if (requestCookies?.cookie) {
37-
const t = requestCookies.cookie.split(';').find(c => c.trim().startsWith(`${clientConfig.tokenName}=`))?.split('=')?.[1]
38-
if (t) {
39-
token.value = t
40-
}
31+
const t = useCookie(clientConfig.tokenName!).value
32+
if (t) {
33+
token.value = t
4134
}
4235
} else if (import.meta.client && clientConfig.tokenStorage === 'localStorage') {
4336
token.value = localStorage.getItem(clientConfig.tokenName!)

0 commit comments

Comments
 (0)