⬆️ Upgrade sentry and improve its reliability
This commit is contained in:
@@ -2,11 +2,18 @@ import { TRPCError, initTRPC } from '@trpc/server'
|
||||
import { Context } from './context'
|
||||
import { OpenApiMeta } from 'trpc-openapi'
|
||||
import superjson from 'superjson'
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
|
||||
const t = initTRPC.context<Context>().meta<OpenApiMeta>().create({
|
||||
transformer: superjson,
|
||||
})
|
||||
|
||||
const sentryMiddleware = t.middleware(
|
||||
Sentry.Handlers.trpcMiddleware({
|
||||
attachRpcInput: true,
|
||||
})
|
||||
)
|
||||
|
||||
const isAuthed = t.middleware(({ next, ctx }) => {
|
||||
if (!ctx.user?.id) {
|
||||
throw new TRPCError({
|
||||
@@ -20,10 +27,12 @@ const isAuthed = t.middleware(({ next, ctx }) => {
|
||||
})
|
||||
})
|
||||
|
||||
const finalMiddleware = sentryMiddleware.unstable_pipe(isAuthed)
|
||||
|
||||
export const middleware = t.middleware
|
||||
|
||||
export const router = t.router
|
||||
|
||||
export const publicProcedure = t.procedure
|
||||
export const publicProcedure = t.procedure.use(sentryMiddleware)
|
||||
|
||||
export const authenticatedProcedure = t.procedure.use(isAuthed)
|
||||
export const authenticatedProcedure = t.procedure.use(finalMiddleware)
|
||||
|
||||
Reference in New Issue
Block a user