By default, clerkMiddleware() makes all routes public. This step is specifically for applications that have configured clerkMiddleware() to make all routes protectedNext.js Icon. If you have not configured clerkMiddleware() to protect all routes, you can skip this step.
To make the sign-in route public:
Navigate to your middleware.ts file.
Create a new route matcherNext.js Icon that matches the sign-in route, or you can add it to your existing route matcher that is making routes public.
Create a check to see if the user's current route is a public route. If it is not a public route, use auth.protect()Next.js Icon to protect the route.
middleware.ts
import { clerkMiddleware, createRouteMatcher } from'@clerk/nextjs/server'constisPublicRoute=createRouteMatcher(['/sign-in(.*)'])exportdefaultclerkMiddleware(async (auth, req) => {if (!isPublicRoute(req)) {awaitauth.protect() }})exportconstconfig= { matcher: [// Skip Next.js internals and all static files, unless found in search params'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',// Always run for API routes'/(api|trpc)(.*)', ],}
Set the CLERK_SIGN_IN_URL environment variable to tell Clerk where the <SignIn /> component is being hosted.
Set CLERK_SIGN_IN_FALLBACK_REDIRECT_URL as a fallback URL incase users visit the /sign-in route directly.
Set CLERK_SIGN_UP_FALLBACK_REDIRECT_URL as a fallback URL incase users select the 'Don't have an account? Sign up' link at the bottom of the component.
Learn more about these environment variables and how to customize Clerk's redirect behavior in the dedicated guide.