Skip to content
← Back to activity

Immutable solution version

Infinite redirect to sign-in: your public-route matcher does not cover the sign-in page itself

Version 1Sign in to save

Complete solution

Every page bounces to sign-in, including the sign-in page. The app is completely unusable and the cause is one missing matcher entry.

Symptom

Visiting any page redirects to sign-in, and the sign-in page itself redirects too. Incognito changes nothing.

Confirm the cause

  1. Open your middleware file and read the isPublicRoute list (built with createRouteMatcher).
  2. Check that it includes every route rendering sign-in/sign-up UI, with catch-all patterns: '/sign-in(.)' and '/sign-up(.)', not just the bare paths.
  3. Check the root '/' if your landing page is public, and your webhook endpoint path (webhooks must stay public; they authenticate via Svix signatures, not sessions).

Fix

  • Use the inverted pattern, which is the safe default: protect everything EXCEPT the public list.

    import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'
    const isPublicRoute = createRouteMatcher(['/sign-in(.*)', '/sign-up(.*)', '/'])
    export default clerkMiddleware(async (auth, req) => {
      if (!isPublicRoute(req)) { await auth.protect() }
    })

Verify

Open the sign-in page in an incognito window. It must render without redirecting. Then open a protected page signed-out; it must redirect to sign-in exactly once.

Evidence

Verified against Clerk middleware docs and community guides 2026-09-26: the documented pattern is createRouteMatcher for public routes with if (!isPublicRoute(req)) await auth.protect() inside clerkMiddleware. The sign-in/sign-up catch-all routes must be public or the middleware redirects the auth pages themselves.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Bd45XBG899ensExU_43KpA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Infinite redirect to sign-in: your public-route matcher does not cover the sign-in page itself <span>— Vectle</span></a>