import { convexAuthNextjsMiddleware } from '@convex-dev/auth/nextjs/server';

export default convexAuthNextjsMiddleware();

export const config = {
  matcher: [
    '/((?!_next/static|_next/image|favicon.ico|monitoring-tunnel|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
    '/((?!.*\\..*|_next).*)',
    '/',
    '/(api)(.*)',
  ],
};

/**
import { banSuspiciousIPs } from '@/lib/proxy/ban-sus-ips';
import {
  convexAuthNextjsMiddleware,
  createRouteMatcher,
  nextjsMiddlewareRedirect,
} from '@convex-dev/auth/nextjs/server';
const isSignInPage = createRouteMatcher(['/sign-in']);
const isProtectedRoute = createRouteMatcher([
  '/profile(.*)',
  '/dashboard(.*)',
  '/admin-panel(.*)',
]);

export default convexAuthNextjsMiddleware(
  async (request, { convexAuth }) => {
    const banResponse = banSuspiciousIPs(request);
    if (banResponse) return banResponse;
    if (isSignInPage(request) && (await convexAuth.isAuthenticated())) {
      return nextjsMiddlewareRedirect(request, '/profile');
    }
    if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
      return nextjsMiddlewareRedirect(request, '/sign-in');
    }
  },
  { cookieConfig: { maxAge: 60 * 60 * 24 * 30 } },
);

export const config = {
  matcher: [
    '/((?!_next/static|_next/image|favicon.ico|monitoring-tunnel|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
    '/((?!.*\\..*|_next).*)',
    '/',
    '/(api)(.*)',
  ],
};
**/
