export async function middleware(request: NextRequest) {
const { data: session } = await betterFetch("/api/auth/get-session", {
baseURL:
process.env.NODE_ENV === "production"
? process.env.NEXT_PUBLIC_BASE_URL
: request.nextUrl.origin,
headers: {
cookie: request.headers.get("cookie") || "",
},
});
const { nextUrl } = request;
const { pathname } = nextUrl;
if (session && guestPaths.includes(pathname)) {
return NextResponse.redirect(new URL("/", request.url));
}
if (!session && protectedPaths.some((path) => pathname.startsWith(path))) {
return NextResponse.redirect(
new URL(`/hesap/giris?next=${pathname}`, request.url)
);
}
return NextResponse.next();
}
export const config = {
matcher: [
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
],
};
export async function middleware(request: NextRequest) {
const { data: session } = await betterFetch("/api/auth/get-session", {
baseURL:
process.env.NODE_ENV === "production"
? process.env.NEXT_PUBLIC_BASE_URL
: request.nextUrl.origin,
headers: {
cookie: request.headers.get("cookie") || "",
},
});
const { nextUrl } = request;
const { pathname } = nextUrl;
if (session && guestPaths.includes(pathname)) {
return NextResponse.redirect(new URL("/", request.url));
}
if (!session && protectedPaths.some((path) => pathname.startsWith(path))) {
return NextResponse.redirect(
new URL(`/hesap/giris?next=${pathname}`, request.url)
);
}
return NextResponse.next();
}
export const config = {
matcher: [
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
],
};