mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-02-04 06:07:54 +01:00
update recipes
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
The `createContext`-function is called for each incoming request so here you can add contextual information about the calling user from the request object.
|
The `createContext`-function is called for each incoming request so here you can add contextual information about the calling user from the request object.
|
||||||
|
|
||||||
## Create context from request headers
|
### Create context from request headers
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// ~/server/trpc/index.ts
|
// ~/server/trpc/index.ts
|
||||||
@@ -35,7 +35,7 @@ type Context = trpc.inferAsyncReturnType<typeof createContext>
|
|||||||
// [..] Define API handler and app router
|
// [..] Define API handler and app router
|
||||||
```
|
```
|
||||||
|
|
||||||
## Option 1: Authorize using resolver
|
### Option 1: Authorize using resolver
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
export const router = trpc
|
export const router = trpc
|
||||||
@@ -60,7 +60,7 @@ export const router = trpc
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Option 2: Authorize using middleware
|
### Option 2: Authorize using middleware
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import * as trpc from '@trpc/server'
|
import * as trpc from '@trpc/server'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
tRPC works out-of-the-box with yup/superstruct/zod/myzod/custom validators.
|
tRPC works out-of-the-box with yup/superstruct/zod/myzod/custom validators.
|
||||||
|
|
||||||
## Input Validation
|
### Input Validation
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// ~/server/trpc/index.ts
|
// ~/server/trpc/index.ts
|
||||||
@@ -24,7 +24,7 @@ export const router = trpc
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output Validation
|
### Output Validation
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// ~/server/trpc/index.ts
|
// ~/server/trpc/index.ts
|
||||||
|
|||||||
Reference in New Issue
Block a user