-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproxy.ts
More file actions
19 lines (15 loc) · 793 Bytes
/
Copy pathproxy.ts
File metadata and controls
19 lines (15 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { NextResponse } from 'next/server';
import { dateKey } from '@/features/calendar/calendar-utils';
import { SESSION_COOKIE } from '@/features/user/session';
import type { NextRequest } from 'next/server';
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
const isPublic = pathname === '/login' || pathname === '/logout' || pathname.startsWith('/book');
const hasSession = request.cookies.has(SESSION_COOKIE);
if (!hasSession && !isPublic) return NextResponse.redirect(new URL('/login', request.url));
if (pathname === '/') return NextResponse.redirect(new URL(`/calendar/${dateKey(new Date())}`, request.url));
return NextResponse.next();
}
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.).*)'],
};