Chirp Tutorial: tRPC failed on <no-path>:

Following along with the theo turtorial https://youtu.be/YkOSUVzOAA4?t=5612

I have my trpc.ts file nearly identical but I run into this error:
tRPC failed on <no-path>: You need to use "withClerkMiddleware" in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs

It's pretty much the exact same file yet I get this error. Just makes no sense. Reproduction Repo: https://github.com/Apestein/chirp

import { type CreateNextContextOptions } from "@trpc/server/adapters/next"
import { prisma } from "~/server/db"

export const createTRPCContext = (opts: CreateNextContextOptions) => {
  const { req } = opts
  const userId = getAuth(req).userId
  return {
    prisma,
    userId,
  }
}

import { TRPCError, initTRPC } from "@trpc/server"
import superjson from "superjson"
import { ZodError } from "zod"
import { getAuth } from "@clerk/nextjs/server"

const t = initTRPC.context<typeof createTRPCContext>().create({
  transformer: superjson,
  errorFormatter({ shape, error }) {
    return {
      ...shape,
      data: {
        ...shape.data,
        zodError:
          error.cause instanceof ZodError ? error.cause.flatten() : null,
      },
    }
  },
})

export const createTRPCRouter = t.router

export const publicProcedure = t.procedure

const enforceUserIsAuthed = t.middleware(async ({ ctx, next }) => {
  if (!ctx.userId)
    throw new TRPCError({
      code: "UNAUTHORIZED",
    })

  return next({
    ctx: {
      userId: ctx.userId,
    },
  })
})

export const privateProcedure = t.procedure.use(enforceUserIsAuthed)
Was this page helpful?