mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-25 09:20:33 +01:00
fix: server storage and incorrect imports
This commit is contained in:
@@ -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,
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user