-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmiddleware.ts
More file actions
27 lines (25 loc) · 809 Bytes
/
middleware.ts
File metadata and controls
27 lines (25 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { NextRequest, NextResponse } from 'next/server';
// import { getSessionCookie } from 'better-auth';
// protects routes by redirecting to login page if user is not authenticated
export async function middleware(request: NextRequest) {
// const sessionCookie = getSessionCookie(request);
// console.log('Session Cookie:', sessionCookie);
const sessionCookie = request.cookies.get('better-auth.session_token');
// console.log('All Cookies:', manualSessionCookie);
// redirect to profile if no session cookie
if (!sessionCookie) {
return NextResponse.redirect(new URL('/profile', request.url));
}
return NextResponse.next();
}
// on what routes will it apply?
export const config = {
matcher: [
'/models',
'/chat',
'/settings',
'/documents',
'/prompts',
'/chat/all-chats',
],
};