diff --git a/proxy.ts b/proxy.ts index cc4c2f7..2034e40 100644 --- a/proxy.ts +++ b/proxy.ts @@ -6,16 +6,17 @@ export default auth((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) { - const url = nextUrl.clone(); - url.pathname = "/login"; - return NextResponse.redirect(url); + return NextResponse.redirect(new URL("/login", baseUrl)); } if (isLoggedIn && isLoginPage) { - const url = nextUrl.clone(); - url.pathname = "/dashboard"; - return NextResponse.redirect(url); + return NextResponse.redirect(new URL("/dashboard", baseUrl)); } return NextResponse.next();