26 lines
615 B
TypeScript
26 lines
615 B
TypeScript
import { NextResponse, type NextRequest } from 'next/server'
|
|
|
|
const PUBLIC_PATHS = ['/login', '/api/auth']
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const { pathname } = request.nextUrl
|
|
|
|
if (PUBLIC_PATHS.some((p) => pathname.startsWith(p))) {
|
|
return NextResponse.next()
|
|
}
|
|
|
|
const session = request.cookies.get('better-auth.session_token')
|
|
|
|
if (!session) {
|
|
return NextResponse.redirect(new URL('/login', request.url))
|
|
}
|
|
|
|
return NextResponse.next()
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
'/((?!_next/static|_next/image|favicon.ico|icons|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
|
|
],
|
|
}
|