feat(auth): Better Auth, kullanıcı adı ile giriş, DAL ve proxy

- MongoDB/Mongoose bağlantıları, kayıt kapalı, admin + username plugin, rate limit
- DAL: getCurrentUser, requireSession, requireRole, getActionUser
- Kullanıcı adı normalizasyonu: İ/I/ı → i (tr-TR 'ADMIN' → 'admın' hatası)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 02:02:00 +03:00
parent 381214c2cb
commit 5191a5cce1
14 changed files with 319 additions and 4 deletions
+22
View File
@@ -0,0 +1,22 @@
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.
matcher: [
"/((?!login|api/auth|api/health|_next/static|_next/image|brand/|icons/|favicon.ico|icon.png|apple-icon.png|manifest.webmanifest|robots.txt).*)",
],
};