Files
aaronai-web/proxy.ts
T

30 lines
767 B
TypeScript

import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
// Allow login page and public assets
if (
pathname.startsWith('/login') ||
pathname.startsWith('/_next') ||
pathname.startsWith('/manifest.json') ||
pathname.startsWith('/icon') ||
pathname.startsWith('/favicon')
) {
return NextResponse.next();
}
// Check for session cookie
const session = request.cookies.get('aaronai_session');
if (!session?.value) {
return NextResponse.redirect(new URL('/login', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};