16 lines
379 B
TypeScript
16 lines
379 B
TypeScript
import type { Context } from './context'
|
|
import { initTRPC } from '@trpc/server'
|
|
|
|
const t = initTRPC.context<Context>().create()
|
|
|
|
export const router = t.router
|
|
|
|
export const publicProcedure = t.procedure
|
|
|
|
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
|
|
if (!ctx.session?.fresh)
|
|
throw new Error('UNAUTHORIZED')
|
|
|
|
return next({ ctx: { ...ctx } })
|
|
})
|