Skip to content

Commit

Permalink
fix: useClientHeaders returning an empty object
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdiboomeri committed Aug 31, 2022
1 parent 019bb20 commit 1e67434
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/runtime/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
}
9 changes: 3 additions & 6 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
},
})

Expand Down

0 comments on commit 1e67434

Please sign in to comment.