11import { NextRequest , NextResponse } from 'next/server' ;
22import { getToken } from 'next-auth/jwt' ;
3- export { default } from 'next-auth/middleware' ;
43
54export const config = {
6- matcher : [ '/dashboard/:path*' , '/sign-in' , '/sign-up' , '/' , '/verify/:path*' ] ,
5+ // Only match routes that genuinely need auth checks.
6+ // Public pages (/, /about, /blog, /faq, /contact, /confessions, /privacy, /terms, /u/*)
7+ // must NOT be in this list — Googlebot needs to crawl them without redirects.
8+ matcher : [ '/dashboard/:path*' , '/sign-in' , '/sign-up' , '/verify/:path*' ] ,
79} ;
810
911export async function middleware ( request : NextRequest ) {
1012 const token = await getToken ( { req : request } ) ;
1113 const url = request . nextUrl ;
1214
13- // Redirect to dashboard if the user is already authenticated
14- // and trying to access sign-in, sign-up, or home page
15+ // Redirect authenticated users away from auth pages to dashboard
1516 if (
1617 token &&
1718 ( url . pathname . startsWith ( '/sign-in' ) ||
@@ -21,6 +22,7 @@ export async function middleware(request: NextRequest) {
2122 return NextResponse . redirect ( new URL ( '/dashboard' , request . url ) ) ;
2223 }
2324
25+ // Redirect unauthenticated users away from dashboard to sign-in
2426 if ( ! token && url . pathname . startsWith ( '/dashboard' ) ) {
2527 return NextResponse . redirect ( new URL ( '/sign-in' , request . url ) ) ;
2628 }
0 commit comments