Files
webmailserver/proxy.ts

28 lines
830 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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).*)"],
};