import { type NextRequest, NextResponse } from 'next/server';
import { updateSession } from '@/utils/supabase/middleware';
export async function middleware(request: NextRequest) {
const response = await updateSession(request);
// Add security headers to all responses
const headers = response.headers;
// Ensure HSTS is set
headers.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload');
// Ensure COOP is set
headers.set('Cross-Origin-Opener-Policy', 'same-origin');
// Add Referrer-Policy header
headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
// Add Permissions-Policy header
headers.set(
'Permissions-Policy',
'camera=(), microphone=(), geolocation=(), interest-cohort=()'
);
return response;
}
export const config = {
matcher: [
/*
* Match all request paths except:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - images - .svg, .png, .jpg, .jpeg, .gif, .webp
* Feel free to modify this pattern to include more paths.
*/
'/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'
]
};