mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-14 12:14:40 +01:00
update docs
This commit is contained in:
@@ -17,19 +17,15 @@ import type { H3Event } from 'h3'
|
|||||||
import { inferAsyncReturnType } from '@trpc/server'
|
import { inferAsyncReturnType } from '@trpc/server'
|
||||||
import { decodeAndVerifyJwtToken } from './somewhere/in/your/app/utils'
|
import { decodeAndVerifyJwtToken } from './somewhere/in/your/app/utils'
|
||||||
|
|
||||||
export async function createContext({
|
export async function createContext(event: H3Event) {
|
||||||
req,
|
|
||||||
res,
|
|
||||||
}: H3Event) {
|
|
||||||
// Create your context based on the request object
|
// Create your context based on the request object
|
||||||
// Will be available as `ctx` in all your resolvers
|
// Will be available as `ctx` in all your resolvers
|
||||||
|
|
||||||
// This is just an example of something you might want to do in your ctx fn
|
// This is just an example of something you might want to do in your ctx fn
|
||||||
|
const authorization = getRequestHeader(event, authorization)
|
||||||
async function getUserFromHeader() {
|
async function getUserFromHeader() {
|
||||||
if (req.headers.authorization) {
|
if (authorization) {
|
||||||
const user = await decodeAndVerifyJwtToken(
|
const user = await decodeAndVerifyJwtToken(authorization.split(' ')[1])
|
||||||
req.headers.authorization.split(' ')[1],
|
|
||||||
)
|
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user