mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
update readme
This commit is contained in:
15
README.md
15
README.md
@@ -99,6 +99,21 @@ const {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## useClientHeaders
|
||||||
|
|
||||||
|
A composable that lets you add additional properties to pass to the tRPC Client. It uses [`useStorage`] from [@vueuse/core](https://vueuse.org/core/usestorage).
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const headers = useClientHeaders()
|
||||||
|
|
||||||
|
const { data: token } = await useAsyncQuery(['auth.login', { username, password }])
|
||||||
|
|
||||||
|
headers.value.Authorization = `Bearer ${token}`
|
||||||
|
|
||||||
|
// All client calls will now include the Authorization header.
|
||||||
|
// For SSR, please follow this until I found a solution https://github.com/trpc/trpc/discussions/1686
|
||||||
|
```
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
trpc-nuxt accepts the following options exposed under `~/server/trpc/index.ts`:
|
trpc-nuxt accepts the following options exposed under `~/server/trpc/index.ts`:
|
||||||
|
|||||||
@@ -84,6 +84,6 @@ export function useClient(): TRPCClient<AppRouter> {
|
|||||||
* @see https://github.com/trpc/trpc/discussions/1686
|
* @see https://github.com/trpc/trpc/discussions/1686
|
||||||
* @param initialValue
|
* @param initialValue
|
||||||
*/
|
*/
|
||||||
export function useClientHeaders(initialValue: MaybeRef<Record<string, any>>) {
|
export function useClientHeaders(initialValue?: MaybeRef<Record<string, any>>) {
|
||||||
return useStorage('trpc-nuxt-header', initialValue || {})
|
return useStorage('trpc-nuxt-header', initialValue || {})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user