UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

20 lines (13 loc) 524 B
import { TRPCError } from '@trpc/server'; import { getJWTPayload } from '@/utils/server/jwt'; import { trpc } from '../init'; export const keyVaults = trpc.middleware(async (opts) => { const { ctx } = opts; if (!ctx.authorizationHeader) throw new TRPCError({ code: 'UNAUTHORIZED' }); try { const jwtPayload = await getJWTPayload(ctx.authorizationHeader); return opts.next({ ctx: { jwtPayload } }); } catch (e) { throw new TRPCError({ code: 'UNAUTHORIZED', message: (e as Error).message }); } });