
import { withAuth } from "next-auth/middleware";

export default withAuth(
  function middleware(req) {
    // Additional middleware logic can go here
  },
  {
    callbacks: {
      authorized: ({ token, req }) => {
        // Allow access to admin pages only for admin users
        if (req.nextUrl.pathname.startsWith('/admin/dashboard')) {
          return token?.rol === 'admin';
        }
        
        // For other admin pages (like login), allow access
        if (req.nextUrl.pathname.startsWith('/admin')) {
          return true;
        }
        
        return true;
      },
    },
  }
);

export const config = {
  matcher: ['/admin/:path*']
};
