From bcfdc5c27a90568b6f2b36e0ac9eb2a267d37616 Mon Sep 17 00:00:00 2001 From: Deardo Satria Date: Wed, 21 Oct 2026 11:04:10 +0700 Subject: [PATCH] Add proxy.ts --- proxy.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 proxy.ts diff --git a/proxy.ts b/proxy.ts new file mode 100644 index 0000000..35d4006 --- /dev/null +++ b/proxy.ts @@ -0,0 +1,15 @@ +import { NextResponse, type NextRequest } from "next/server"; +import { getSessionCookie } from "better-auth/cookies"; + +export function proxy(request: NextRequest) { + // Only checks that the cookie exists; getCurrentUser() still validates it. + if (!getSessionCookie(request)) { + return NextResponse.redirect(new URL("/login", request.url)); + } + + return NextResponse.next(); +} + +export const config = { + matcher: ["/((?!api|login|_next/static|_next/image|.*\\..*).*)"], +};