import { auth } from "@/auth"; import { NextResponse } from "next/server"; export default auth((req) => { const { pathname } = req.nextUrl; const isLoggedIn = !!req.auth; const isOnLoginPage = pathname === "/login"; // Pages publiques (API auth et teams) if (pathname.startsWith("/api/auth") || pathname.startsWith("/api/teams")) { return NextResponse.next(); } // Si connecté et sur login, rediriger vers home if (isLoggedIn && isOnLoginPage) { return NextResponse.redirect(new URL("/", req.url)); } // Si non connecté et pas sur login, rediriger vers login if (!isLoggedIn && !isOnLoginPage) { return NextResponse.redirect(new URL("/login", req.url)); } return NextResponse.next(); }); export const config = { matcher: [ /* * Match all request paths except for the ones starting with: * - api (API routes) * - _next/static (static files) * - _next/image (image optimization files) * - favicon.ico (favicon file) */ "/((?!_next/static|_next/image|favicon.ico).*)", ], };