| 1 | import { getSessionCookie } from 'better-auth/cookies' |
| 2 | import { type NextRequest, |
| 3 | |
| 4 | import { |
| 5 | DEFAULT_LOGIN_REDIRECT, |
| 6 | getSignInUrl, |
| 7 | isApiAuth, |
| 8 | isAuthRoute, |
| 9 | isPublicRoute, |
| 10 | } from '@/routes' |
| 11 | |
| 12 | export function proxy(request |
| 13 | const session = |
| 14 | |
| 15 | const pathname = |
| 16 | |
| 17 | if (isApiAuth(pathname |
| 18 | return NextResponse.next |
| 19 | } |
| 20 | |
| 21 | if (isAuthRoute(pathname |
| 22 | if (session) { |
| 23 | return NextResponse.redirect |
| 24 | } |
| 25 | return NextResponse.next |
| 26 | } |
| 27 | |
| 28 | if (!(session |
| 29 | return NextResponse.redirect |
| 30 | } |
| 31 | |
| 32 | return NextResponse.next |
| 33 | } |
| 34 | |
| 35 | export const config = |
| 36 | matcher: [ |
| 37 | /* |
| 38 | * Match all request paths except for the ones starting with: |
| 39 | * - _next/static (static files) |
| 40 | * - _next/image (image optimization files) |
| 41 | * - favicon.ico (favicon file) |
| 42 | * Feel free to modify this pattern to include more paths. |
| 43 | */ |
| 44 | '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)', |
| 45 | ], |
| 46 | } |