Skip to content

Commit 6000738

Browse files
committed
feat: enhance proxy function with session cookie validation
- Updated the proxy function to accept a NextRequest parameter and check for session cookies. - Implemented redirection to the sign-in page if no valid session cookie is found. - Adjusted the matcher configuration to apply the proxy only to the '/dashboard' route.
1 parent 6eae7d8 commit 6000738

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

proxy.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { getSessionCookie } from 'better-auth/cookies';
2+
import type { NextRequest } from 'next/server';
13
import { NextResponse } from 'next/server';
24

3-
export async function proxy() {
5+
export async function proxy(request: NextRequest) {
6+
const cookies = getSessionCookie(request);
7+
if (!cookies) {
8+
return NextResponse.redirect(new URL('/auth?mode=signin', request.url));
9+
}
410
return NextResponse.next();
511
}
612

713
export const config = {
8-
matcher: ['/'],
14+
matcher: ['/dashboard'],
915
};

0 commit comments

Comments
 (0)