import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'; /** * Clerk middleware for route protection * Protects all API routes except public endpoints */ const isPublicRoute = createRouteMatcher([ '/api/auth(.*)', '/api/health', '/api/config(.*)', // Allow config endpoints for iOS to fetch keys ]); export default clerkMiddleware((auth, req) => { if (!isPublicRoute(req)) { auth().protect(); } }); export const config = { matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'], };