diff --git a/components/sidebar.tsx b/components/sidebar.tsx index e9491851..035cf74f 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -57,10 +57,13 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) { pathname }); - // Redirect to signin if no session + // Show loading state while session is being checked + if (status === 'loading') { + return null; + } + + // Show nothing if not authenticated (middleware will handle redirect) if (status === 'unauthenticated') { - console.log('No session, redirecting to signin'); - router.push('/signin'); return null; } diff --git a/middleware.ts b/middleware.ts index 4c34f904..a302d1b7 100644 --- a/middleware.ts +++ b/middleware.ts @@ -29,8 +29,13 @@ export default withAuth( return true; } - // Require authentication for protected API endpoints - return !!token; + // For protected API endpoints, check if the request has a valid session + if (!token) { + // Return 401 for API routes instead of redirecting + return false; + } + + return true; } // For all other routes, require a valid token