fix: useClientHeaders returning an empty object

This commit is contained in:
Mahdi Boomeri
2022-08-31 19:13:29 +04:30
parent 019bb20e50
commit 1e67434a8f
2 changed files with 4 additions and 8 deletions

View File

@@ -9,7 +9,6 @@ import type { ProcedureRecord, inferHandlerInput, inferProcedureInput, inferProc
import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client'
import { objectHash } from 'ohash'
import type { Ref } from 'vue'
import { useStorage } from '@vueuse/core'
import { useAsyncData, useNuxtApp, useState } from '#app'
import type { router } from '~/server/trpc'
@@ -79,5 +78,5 @@ export function useClient(): TRPCClient<AppRouter> {
}
export function useClientHeaders(initialValue: MaybeRef<Record<string, any>> = {}): Ref<Record<string, any>> {
return useStorage('trpc-nuxt-header', initialValue)
return useState('trpc-nuxt-header', () => initialValue)
}

View File

@@ -13,13 +13,10 @@ export default defineNuxtPlugin((nuxtApp) => {
const client = trpc.createTRPCClient<AppRouter>({
url: `${config.baseURL}${config.endpoint}`,
headers: () => {
if (nuxtApp.ssrContext) {
return {
...unref(otherHeaders),
...headers,
}
return {
...unref(otherHeaders),
...headers,
}
return {}
},
})