Skip to content

fix: opt in to import.meta.* properties #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/components/GithubDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const { getToken, onLogin, onLogout } = useApollo()
const githubToken = ref<string | null>(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')
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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') {
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> } = {}

Expand All @@ -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!)
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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])))
}
}
Expand Down