31 lines
815 B
TypeScript
31 lines
815 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import type { NextRequest } from 'next/server';
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
// Always allow these through
|
|
if (
|
|
pathname.startsWith('/api/') ||
|
|
pathname.startsWith('/login') ||
|
|
pathname.startsWith('/_next') ||
|
|
pathname.startsWith('/manifest.json') ||
|
|
pathname.startsWith('/icon') ||
|
|
pathname.startsWith('/favicon')
|
|
) {
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Check for session cookie on all other routes
|
|
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).*)'],
|
|
};
|