Files
sofa/proxy.ts
T
jake e19f29a90f Remove auth redirect logic from proxy middleware
- Drop `authRoutes` set and both redirect branches so the proxy no
  longer redirects logged-in users away from auth pages or
  unauthenticated users away from protected pages
2026-03-08 19:17:52 -04:00

25 lines
787 B
TypeScript

import { getSessionCookie } from "better-auth/cookies";
import { type NextRequest, NextResponse } from "next/server";
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
// this is ONLY for optimistic redirects, it does not provide any actual security
const sessionCookie = getSessionCookie(request);
// Special case for root: becomes dashboard if logged in, landing page if not
if (pathname === "/") {
return sessionCookie
? NextResponse.rewrite(new URL("/dashboard", request.url))
: NextResponse.next();
}
return NextResponse.next();
}
export const config = {
matcher: [
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|manifest.webmanifest|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
],
};