Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions apps/web/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";

// Whitelist approach: ONLY dashboard requires auth
// Landing page, docs, pricing, etc. - all public
const isProtectedRoute = createRouteMatcher([
"/dashboard(.*)",
]);
const isProtectedRoute = createRouteMatcher(["/dashboard(.*)"]);

// Paths that should completely bypass Clerk
const BYPASS_PATHS = ["/sitemap.xml", "/robots.txt"];

export default clerkMiddleware(async (auth, req) => {
const pathname = req.nextUrl.pathname;

// Bypass Clerk entirely for sitemap and robots
if (BYPASS_PATHS.includes(pathname)) {
return NextResponse.next();
}

if (isProtectedRoute(req)) {
await auth.protect();
}
});

export const config = {
matcher: [
// Skip Next.js internals and static files (including xml for sitemap, txt for robots)
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest|xml|txt)).*)",
// Skip Next.js internals and static files
"/((?!_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)(.*)",
],
Expand Down
Loading