/* eslint-disable typescript/promise-function-async */ import {initTRPC, TRPCError} from '@trpc/server'; import {type Context} from './context.js'; const t = initTRPC.context().create(); export const {router, createCallerFactory, procedure: publicProcedure} = t; export const protectedProcedure = t.procedure.use(({ctx, next}) => { if (!ctx.user) { throw new TRPCError({code: 'UNAUTHORIZED'}); } return next({ ctx: { user: ctx.user, }, }); });