fix: server storage and incorrect imports

This commit is contained in:
Robert Soriano
2022-05-24 10:01:19 -07:00
parent 96ebff619e
commit 38ac520b97
3 changed files with 5 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import * as trpc from '@trpc/client'
import { useClientHeaders } from './client'
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app'
import type { router } from '~/server/trpc'
@@ -7,17 +8,12 @@ declare type AppRouter = typeof router
export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig().public.trpc
const headers = useRequestHeaders()
const otherHeaders = useClientHeaders()
const client = trpc.createTRPCClient<AppRouter>({
url: `${config.baseURL}${config.trpcURL}`,
headers: () => {
let otherHeaders = {}
if (!process.server) {
const key = 'trpc-nuxt-header'
otherHeaders = JSON.parse(localStorage.getItem(key) || JSON.stringify({}))
}
return {
...otherHeaders,
...unref(otherHeaders),
...headers,
}
},