@@ -28,6 +28,11 @@ export async function middleware(request: NextRequest) {
2828
2929 const { pathname } = request . nextUrl ;
3030
31+ // Allow access to auth callback pages
32+ if ( pathname === "/success" || pathname === "/error" ) {
33+ return NextResponse . next ( ) ;
34+ }
35+
3136 if ( ! isProtectedPath ( pathname ) ) {
3237 return NextResponse . next ( ) ;
3338 }
@@ -49,7 +54,7 @@ export async function middleware(request: NextRequest) {
4954 "User-Agent" : request . headers . get ( "user-agent" ) || "Next.js middleware" ,
5055 } ,
5156 withCredentials : true ,
52- timeout : 5000 ,
57+ timeout : 10000 , // Increased timeout to 10 seconds
5358 } ) ;
5459
5560 if ( response . status >= 200 && response . status < 300 ) {
@@ -63,6 +68,13 @@ export async function middleware(request: NextRequest) {
6368 } catch ( error ) {
6469 console . error ( "Middleware auth check failed" , error ) ;
6570
71+ // If it's a timeout error and user has access_token cookie, let them through
72+ // The client-side auth check will handle the validation
73+ if ( axios . isAxiosError ( error ) && error . code === "ETIMEDOUT" && hasRequiredCookie ) {
74+ console . log ( "API timeout but user has valid cookie, allowing access" ) ;
75+ return NextResponse . next ( ) ;
76+ }
77+
6678 const loginUrl = new URL ( "/login" , request . url ) ;
6779 loginUrl . searchParams . set ( "redirect" , pathname ) ;
6880
0 commit comments