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

export default withAuth(
  function middleware() {
    // Le middleware s'exécute seulement si l'utilisateur est authentifié
    // grâce à withAuth
  },
  {
    callbacks: {
      authorized: ({ token }) => {
        // Vérifier si l'utilisateur a un token valide
        return !!token;
      },
    },
  }
);

export const config = {
  matcher: [
    /*
     * Match all request paths except for the ones starting with:
     * - api/auth (NextAuth routes)
     * - login (login page)
     * - register (registration page)
     * - profile (profile page)
     * - _next/static (static files)
     * - _next/image (image optimization files)
     * - favicon.ico (favicon file)
     * - public files (images, etc.)
     */
    '/((?!api/auth|login|register|profile|_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
  ],
};
