import { NextResponse } from "next/server"; import { auth } from "./auth"; export default auth((req) => { const { nextUrl } = req; const isLoggedIn = !!req.auth; const isLoginPage = nextUrl.pathname === "/login"; // Proxy arkasında çalışırken doğru adresi alabilmek için const host = req.headers.get("x-forwarded-host") || req.headers.get("host") || "localhost:3000"; const proto = req.headers.get("x-forwarded-proto") || "http"; const baseUrl = `${proto}://${host}`; if (!isLoggedIn && !isLoginPage) { return NextResponse.redirect(new URL("/login", baseUrl)); } if (isLoggedIn && isLoginPage) { return NextResponse.redirect(new URL("/dashboard", baseUrl)); } return NextResponse.next(); }); export const config = { matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"], };