Clerk middleware + trpc

Hello, I don't understand why i can't use authMiddlewarefrom Clerck with TRPC. In the docs he say use withClerkMiddleware but you can't setup public / private route.
2 Replies
Meyer
MeyerOP2y ago
Clerk: A request for a static file or a NextJS internal route was intercepted by authMiddleware. Usually, these requests require no authentication logic so the authMiddleware ignores them by default.
However, for improved performance, these requests should be ignored using the default config.matcher API exported from your middleware file.
The request URL was: http://localhost:3000/api/trpc/activites.getAll,spots.getAll,profiles.search?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%221%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%222%22%3A%7B%22json%22%3A%7B%22gender%22%3A%22indifferent%22%2C%22activities%22%3A%5B%5D%2C%22spots%22%3A%5B%5D%7D%7D%7D.

To resolve this warning, open your middleware file, set your config.matcher as shown below and restart your dev server:

export const config = {
matcher: ["/((?!.*\\..*|_next).*)","/"],
};

If you intentionally want to run the authMiddleware for this route, you can exclude it from the default ignoredRoutes.
Clerk: A request for a static file or a NextJS internal route was intercepted by authMiddleware. Usually, these requests require no authentication logic so the authMiddleware ignores them by default.
However, for improved performance, these requests should be ignored using the default config.matcher API exported from your middleware file.
The request URL was: http://localhost:3000/api/trpc/activites.getAll,spots.getAll,profiles.search?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%221%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%222%22%3A%7B%22json%22%3A%7B%22gender%22%3A%22indifferent%22%2C%22activities%22%3A%5B%5D%2C%22spots%22%3A%5B%5D%7D%7D%7D.

To resolve this warning, open your middleware file, set your config.matcher as shown below and restart your dev server:

export const config = {
matcher: ["/((?!.*\\..*|_next).*)","/"],
};

If you intentionally want to run the authMiddleware for this route, you can exclude it from the default ignoredRoutes.
//middleware.ts
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware({ publicRoutes: ["/"] });

export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
//middleware.ts
import { authMiddleware } from "@clerk/nextjs";

export default authMiddleware({ publicRoutes: ["/"] });

export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
miggg
miggg2y ago
i also dont understand. i just want authmiddleware to ignore the "/" and the "/(api|trpc)(.)", like in config. so i did this in middleware.ts: ``` import { authMiddleware } from "@clerk/nextjs"; export default authMiddleware({ publicRoutes: ["/", "/(api|trpc)(.)"], }); export const config = { matcher: ["/((?!.\..|_next).)", "/", "/(api|trpc)(.)"], }; ``` this feels wrong. but trpc works now.
Want results from more Discord servers?
Add your server