Skip to content

Commit

Permalink
fix: opt in to import.meta.* properties
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 25, 2024
1 parent 90f4765 commit e8c89e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
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

0 comments on commit e8c89e4

Please sign in to comment.