A tRPC base procedure loses its sign-in check
A blog API on tRPC and Prisma. The change takes the session check out of protectedProcedure, the base procedure deletePost is built from, so the mutation now runs for a visitor who is not signed in.
The check is written in the function handed to .use, and Aburi reads that function as the base procedure's body: the report lists the removed guard and the TRPCError it threw as logic changes on protectedProcedure. The mutation's own code did not change, so the report names only the base procedure.
Configuration
json
{
"$schema": "https://aburi.dev/schema/aburi.config.v1.json",
"languages": ["@aburi/lang-typescript"],
"frameworks": ["@aburi/framework-trpc"],
"effects": ["@aburi/effects-prisma"]
}The change
diff
diff --git a/src/trpc.ts b/src/trpc.ts
index 37e8728..9aa0597 100644
--- a/src/trpc.ts
+++ b/src/trpc.ts
@@ -1,4 +1,4 @@
-import { initTRPC, TRPCError } from "@trpc/server"
+import { initTRPC } from "@trpc/server"
import type { Context } from "./context"
const t = initTRPC.context<Context>().create()
@@ -8,8 +8,5 @@ export const router = t.router
export const publicProcedure = t.procedure
export const protectedProcedure = t.procedure.use(({ ctx, next }) => {
- if (!ctx.session?.user) {
- throw new TRPCError({ code: "UNAUTHORIZED" })
- }
- return next({ ctx: { user: ctx.session.user } })
+ return next({ ctx: { user: ctx.session?.user } })
})What aburi diff reports
Aburi diff: HEAD~1..HEAD
Summary: +0 added · -0 removed · ~1 changed · 0 moved · 0 moved+changed
🔧 Logic changes
protectedProcedure (const)
File: src/trpc.ts:10
- rules removed:
- guard:
!ctx.session?.user(L11) - throw:
TRPCError(L12)
- guard:
- calls removed:
TRPCError(L12)
🧵 Slice View
Standalone changes
1 symbol with no resolved call to or from another symbol in this view
protectedProcedure— logic and syntax changed ·src/trpc.ts:10