Compare commits

..

4 Commits

Author SHA1 Message Date
Robert Soriano
af89f32275 release v0.1.19 2022-05-26 07:27:20 -07:00
Robert Soriano
1f27b871fb fix: unref import from vue 2022-05-26 07:21:42 -07:00
Robert Soriano
281e4c05a0 release v0.1.18 2022-05-24 10:01:23 -07:00
Robert Soriano
38ac520b97 fix: server storage and incorrect imports 2022-05-24 10:01:19 -07:00
4 changed files with 7 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "trpc-nuxt",
"type": "module",
"version": "0.1.17",
"version": "0.1.19",
"packageManager": "pnpm@7.1.1",
"license": "MIT",
"main": "./dist/module.cjs",

View File

@@ -1,10 +1,8 @@
<script setup lang="ts">
const client = useClient()
const headers = useClientHeader({ authorization: 'asdada' })
const headers = useClientHeaders()
const { data: todos, pending, error, refresh } = await useAsyncQuery(['getTodos'])
console.log(headers.value)
const addHeader = () => {
// headers.value.cookie = 'counter=69'
console.log(headers.value)

View File

@@ -38,7 +38,7 @@ export default defineNuxtModule<ModuleOptions>({
imports.push(
{ name: 'useClient', from: join(runtimeDir, 'client') },
{ name: 'useAsyncQuery', from: join(runtimeDir, 'client') },
{ name: 'useClientHeader', from: join(runtimeDir, 'client') },
{ name: 'useClientHeaders', from: join(runtimeDir, 'client') },
)
})

View File

@@ -1,4 +1,6 @@
import * as trpc from '@trpc/client'
import { unref } from 'vue'
import { useClientHeaders } from './client'
import { defineNuxtPlugin, useRequestHeaders, useRuntimeConfig } from '#app'
import type { router } from '~/server/trpc'
@@ -7,17 +9,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,
}
},