Reputation: 1664
I'm using Clerk for authentication in my app. I've set protected routes using middleware like so:
import { authMiddleware } from "@clerk/nextjs";
export default authMiddleware({
publicRoutes: ["/sign-in", "/sign-up"],
});
export const config = {
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
};
The route /
is not public without being signed in. Yet I can still navigate to it. Where am I going wrong?
Upvotes: 1
Views: 2792
Reputation: 366
I see that you figured it out, but for anyone else who has this issue, middleware.ts
needs to be in the root of your project per the docs. In other words, if you're using the app directory, it would go in the same folder that contains the app directory (e.g., C:\Users\[your name]\[your project]\middleware.ts
).
Upvotes: 5