From 1d7be4642d7e2b72b4bb5b6624d8cf2e7743a2e3 Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Thu, 24 Nov 2022 13:07:13 -0800 Subject: [PATCH] update docs --- docs/content/1.get-started/3.tips/3.authorization.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/content/1.get-started/3.tips/3.authorization.md b/docs/content/1.get-started/3.tips/3.authorization.md index 9bfdcee..66ed77e 100644 --- a/docs/content/1.get-started/3.tips/3.authorization.md +++ b/docs/content/1.get-started/3.tips/3.authorization.md @@ -17,19 +17,15 @@ import type { H3Event } from 'h3' import { inferAsyncReturnType } from '@trpc/server' import { decodeAndVerifyJwtToken } from './somewhere/in/your/app/utils' -export async function createContext({ - req, - res, -}: H3Event) { +export async function createContext(event: H3Event) { // Create your context based on the request object // 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 + const authorization = getRequestHeader(event, authorization) async function getUserFromHeader() { - if (req.headers.authorization) { - const user = await decodeAndVerifyJwtToken( - req.headers.authorization.split(' ')[1], - ) + if (authorization) { + const user = await decodeAndVerifyJwtToken(authorization.split(' ')[1]) return user } return null