severity: errorpack: clerkv1.0 core
clerk/middleware-missing-auth-await
`auth()` is not awaited in middleware
npx @pitcheye/check . --pack clerkwhyItBreaks
In Clerk v5+ the middleware is async and `auth()` returns a Promise. Reading `.userId` off the Promise — or calling `.protect()` on it — always yields undefined/falsy, so the guard never rejects and the route stays public.
✖ Bad — triggers errorfixtures/clerk-middleware-missing-auth-await/bad
const { userId } = auth();
if (!userId) auth().protect();✓ Good — passes checkfixtures/clerk-middleware-missing-auth-await/good
const { userId } = await auth();
if (!userId) await auth.protect();suggestedFix
Await the helper: `const { userId } = await auth()` and `await auth.protect()`.
explain_rule({"clerk/middleware-missing-auth-await"})Agent & MCP JSON output contract
{
"ruleId": "clerk/middleware-missing-auth-await",
"pack": "clerk",
"severity": "error",
"file": "apps/web/src/app/api/listings/route.ts",
"line": 6,
"message": "`auth()` / `auth().protect()` called without `await` inside clerkMiddleware",
"whyItBreaks": "In Clerk v5+ the middleware is async and `auth()` returns a Promise. Reading `.userId` off the Promise — or calling `.protect()` on it — always yields undefined/falsy, so the guard never rejects and the route stays public.",
"suggestedFix": "Await the helper: `const { userId } = await auth()` and `await auth.protect()`.",
"docsUrl": "https://pitcheye.dev/rules/clerk-middleware-missing-auth-await"
}Markdown: curl -H "Accept: text/markdown" https://pitcheye.dev/rules/clerk-middleware-missing-auth-await
raw markdown
# clerk/middleware-missing-auth-await
- **severity:** error
- **pack:** clerk
- **docs:** https://pitcheye.dev/rules/clerk-middleware-missing-auth-await
## whyItBreaks
In Clerk v5+ the middleware is async and `auth()` returns a Promise. Reading `.userId` off the Promise — or calling `.protect()` on it — always yields undefined/falsy, so the guard never rejects and the route stays public.
## bad
```ts
const { userId } = auth();
if (!userId) auth().protect();
```
## good
```ts
const { userId } = await auth();
if (!userId) await auth.protect();
```
## suggestedFix
Await the helper: `const { userId } = await auth()` and `await auth.protect()`.
## commands
```bash
npx @pitcheye/check . --pack clerk
```
```json
{"tool":"explain_rule","arguments":{"ruleId":"clerk/middleware-missing-auth-await"}}
```