import { NextResponse } from 'next/server'; import type { NextRequest } from 'next/server'; // Maximum cookie size in bytes (a bit less than 4KB to be safe) const MAX_COOKIE_SIZE = 3800; // This middleware runs before any request export function middleware(request: NextRequest) { // Force NextAuth environment variables at runtime process.env.NEXTAUTH_COOKIE_SIZE_LIMIT = MAX_COOKIE_SIZE.toString(); // Set defaults for cookie security process.env.NEXTAUTH_CALLBACK = 'false'; process.env.NEXTAUTH_SESSION_STORE_SESSION_TOKEN = 'false'; process.env.NEXTAUTH_JWT_STORE_RAW_TOKEN = 'false'; // Continue with the request return NextResponse.next(); } // Configure the middleware to run on specific paths export const config = { matcher: [ // Apply to all routes except static files and api routes that aren't auth '/((?!_next/static|_next/image|favicon.ico|public).*)', ], };