From e8c89e42081df094638f895088fec8470543bb6d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 25 Mar 2024 12:57:07 +0000 Subject: [PATCH] fix: opt in to `import.meta.*` properties --- playground/components/GithubDemo.vue | 2 +- src/runtime/composables.ts | 4 ++-- src/runtime/plugin.ts | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/playground/components/GithubDemo.vue b/playground/components/GithubDemo.vue index 9d0f588d..54b35c81 100644 --- a/playground/components/GithubDemo.vue +++ b/playground/components/GithubDemo.vue @@ -53,7 +53,7 @@ const { getToken, onLogin, onLogout } = useApollo() const githubToken = ref(null) // for testing with cookie `tokenStorage` -if (process.server) { githubToken.value = await getToken('github') } +if (import.meta.server) { githubToken.value = await getToken('github') } onMounted(async () => { githubToken.value = await getToken('github') diff --git a/src/runtime/composables.ts b/src/runtime/composables.ts index cf6182b5..73d73d1e 100644 --- a/src/runtime/composables.ts +++ b/src/runtime/composables.ts @@ -70,7 +70,7 @@ export const useApollo = () => { const tokenName = conf.tokenName! - return conf?.tokenStorage === 'cookie' ? useCookie(tokenName).value : (process.client && localStorage.getItem(tokenName)) || null + return conf?.tokenStorage === 'cookie' ? useCookie(tokenName).value : (import.meta.client && localStorage.getItem(tokenName)) || null } type TAuthUpdate = {token?: string, client?: string, mode: 'login' | 'logout', skipResetStore?: boolean} const updateAuth = async ({ token, client, mode, skipResetStore }: TAuthUpdate) => { @@ -88,7 +88,7 @@ export const useApollo = () => { if (!cookie.value && mode === 'logout') { return } cookie.value = (mode === 'login' && token) || null - } else if (process.client && conf?.tokenStorage === 'localStorage') { + } else if (import.meta.client && conf?.tokenStorage === 'localStorage') { if (mode === 'login' && token) { localStorage.setItem(tokenName, token) } else if (mode === 'logout') { diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 716166fd..5f0884ec 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -13,7 +13,7 @@ import { ref, useCookie, defineNuxtPlugin, useRequestHeaders } from '#imports' import NuxtApollo from '#apollo' export default defineNuxtPlugin((nuxtApp) => { - const requestCookies = (process.server && NuxtApollo.proxyCookies && useRequestHeaders(['cookie'])) || undefined + const requestCookies = (import.meta.server && NuxtApollo.proxyCookies && useRequestHeaders(['cookie'])) || undefined const clients: { [key: string]: ApolloClient } = {} @@ -25,12 +25,12 @@ export default defineNuxtPlugin((nuxtApp) => { if (!token.value) { if (clientConfig.tokenStorage === 'cookie') { - if (process.client) { + if (import.meta.client) { token.value = useCookie(clientConfig.tokenName!).value } else if (requestCookies?.cookie) { token.value = requestCookies.cookie.split(';').find(c => c.trim().startsWith(`${clientConfig.tokenName}=`))?.split('=')?.[1] } - } else if (process.client && clientConfig.tokenStorage === 'localStorage') { + } else if (import.meta.client && clientConfig.tokenStorage === 'localStorage') { token.value = localStorage.getItem(clientConfig.tokenName!) } @@ -60,13 +60,13 @@ export default defineNuxtPlugin((nuxtApp) => { const httpLink = authLink.concat(createHttpLink({ ...(clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions), - uri: (process.client && clientConfig.browserHttpEndpoint) || clientConfig.httpEndpoint, + uri: (import.meta.client && clientConfig.browserHttpEndpoint) || clientConfig.httpEndpoint, headers: { ...(clientConfig?.httpLinkOptions?.headers || {}) } })) let wsLink: GraphQLWsLink | null = null - if (process.client && clientConfig.wsEndpoint) { + if (import.meta.client && clientConfig.wsEndpoint) { const wsClient = createRestartableClient({ ...clientConfig.wsLinkOptions, url: clientConfig.wsEndpoint, @@ -113,7 +113,7 @@ export default defineNuxtPlugin((nuxtApp) => { link, cache, ...(NuxtApollo.clientAwareness && { name: key }), - ...(process.server + ...(import.meta.server ? { ssrMode: true } : { ssrForceFetchDelay: 100 }), connectToDevTools: clientConfig.connectToDevTools || false, @@ -130,7 +130,7 @@ export default defineNuxtPlugin((nuxtApp) => { nuxtApp.payload.data[cacheKey] = cache.extract() }) - if (process.client && nuxtApp.payload.data[cacheKey]) { + if (import.meta.client && nuxtApp.payload.data[cacheKey]) { cache.restore(destr(JSON.stringify(nuxtApp.payload.data[cacheKey]))) } }