Skip to content

Connection refused error with Supabase after implementing protected routes #1788

@Ceejay222

Description

@Ceejay222

When implementing protected routes in a React application using Supabase authentication, users are experiencing connection refused errors with the message "project-id.supabase.co refused to connect". This occurs specifically after adding protected route functionality and affects the application's ability to authenticate users.

Steps to Reproduce

  1. Set up a new React + Vite project with Supabase authentication
  2. Implement protected routes using React Router
  3. Configure Supabase client with authentication
  4. Attempt to access a protected route
  5. Connection is refused with the error: "project-id. superbase.co refused to connect"

Expected Behavior

  • Protected routes should properly authenticate with Supabase
  • No connection refused errors should occur
  • Smooth transition between public and protected routes

Actual Behavior

  • Connection to Supabase is being refused
  • Authentication flow is broken
  • Users cannot access protected routes
  • Application becomes unresponsive

Environment

  • React 18.3.1
  • Vite 5.4.2
  • @supabase/supabase-js latest
  • React Router DOM 6.22.2
  • Browser: Latest Chrome/Firefox
  • OS: Windows/Mac/Linux

Relevant Code

The issue appears after implementing the following authentication flow:

// ProtectedRoute.tsx
export function ProtectedRoute({ children }: ProtectedRouteProps) {
  const { user, initialized } = useAuthStore();
  const location = useLocation();

  if (!initialized) {
    return <LoadingSpinner />;
  }

  if (!user) {
    return <Navigate to="/login" state={{ from: location }} replace />;
  }

  return <>{children}</>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions