Files
butcem/src/proxy.ts
T

25 lines
1.1 KiB
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 { getSessionCookie } from "better-auth/cookies";
import { NextResponse, type NextRequest } from "next/server";
/**
* İYİMSER kontrol: yalnızca oturum cookie'si var mı diye bakar (veritabanına gitmez).
* Cookie yoksa korumalı sayfaları /login'e yönlendirir. Asıl yetki kontrolü lib/dal.ts'de;
* bu katman tek başına güvenlik sağlamaz.
*/
export function proxy(request: NextRequest) {
const hasSessionCookie = Boolean(getSessionCookie(request, { cookiePrefix: "butcem" }));
if (!hasSessionCookie) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
export const config = {
// Herkese açık yollar hariç: giriş, auth ve health API'leri, statik dosyalar, ikonlar, manifest.
// /api/files da hariç: route oturumu kendisi kontrol eder (401) ve proxy büyük yükleme
// gövdelerini tamponlamasın (proxyClientMaxBodySize).
matcher: [
"/((?!login|api/auth|api/health|api/files|_next/static|_next/image|brand/|icons/|favicon.ico|icon.png|apple-icon.png|manifest.webmanifest|robots.txt).*)",
],
};