authMiddleware: How to protect just a single route? #2095
Replies: 2 comments 1 reply
-
// middleware.ts
import { authMiddleware } from "@clerk/nextjs";
// This example protects all routes including api/trpc routes
// Please edit this to allow other routes to be public as needed.
// See https://clerk.com/docs/references/nextjs/auth-middleware for more information about configuring your Middleware
export default authMiddleware({});
export const config = {
matcher: ['/dashboard(.*)'],
}; Learn more about matcher: https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher |
Beta Was this translation helpful? Give feedback.
1 reply
-
For anybody having the same issue, it is not clear in the Clerk documentation that
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Similar to the discussion in #2076, we would like to protect only the
/dashboard
route including its sub-routes in our Next.js 14 app middleware. Most of our content is public, but it is very tedious to include each and every bit in thepublicRoutes
config.We also have a lot of pages at root level, such as
/pricing
,/contact
etc., which we also would like not to list each time a new page is created.What would be the best way to achieve protection of
/dashboard
and/dashboard/*
only? Thanks!Beta Was this translation helpful? Give feedback.
All reactions