import { auth } from '@/auth'; import { NextResponse } from 'next/server'; export default auth((req) => { const { nextUrl } = req; const isAuthed = !!req.auth; const isChatRoute = nextUrl.pathname.startsWith('/chat'); if (isChatRoute && !isAuthed) { const loginUrl = new URL('/login', nextUrl); loginUrl.searchParams.set('callbackUrl', nextUrl.pathname); return NextResponse.redirect(loginUrl); } return NextResponse.next(); }); export const config = { matcher: ['/chat/:path*'], };