pitcheye.dev← All 30 rules
severity: warnpack: supabase-authv1.0 core

supabase-auth/missing-session-refresh-middleware

Middleware never refreshes the Supabase session

npx @pitcheye/check . --pack supabase-auth

whyItBreaks

With @supabase/ssr the access token lives ~1h and is refreshed by the middleware. Without the refresh the session expires mid-visit and every server component starts rendering as signed-out — the classic "randomly logged out" report that is impossible to reproduce locally.

✖ Bad — triggers warnfixtures/supabase-auth-missing-session-refresh-middleware/bad
export function middleware(req: NextRequest) {
  return NextResponse.next();
}
✓ Good — passes checkfixtures/supabase-auth-missing-session-refresh-middleware/good
export async function middleware(req: NextRequest) {
  const supabase = createServerClient(url, key, { cookies: adapter });
  await supabase.auth.getUser();
  return response;
}

suggestedFix

In middleware, build the client with the request/response cookie adapter and `await supabase.auth.getUser()` on every request, before returning the response.

explain_rule({"supabase-auth/missing-session-refresh-middleware"})

Agent & MCP JSON output contract

{
  "ruleId": "supabase-auth/missing-session-refresh-middleware",
  "pack": "supabase-auth",
  "severity": "warn",
  "file": "apps/web/src/app/dashboard/page.tsx",
  "line": 6,
  "message": "a middleware module with no `supabase.auth.getUser()` while the repo uses @supabase/ssr",
  "whyItBreaks": "With @supabase/ssr the access token lives ~1h and is refreshed by the middleware. Without the refresh the session expires mid-visit and every server component starts rendering as signed-out — the classic \"randomly logged out\" report that is impossible to reproduce locally.",
  "suggestedFix": "In middleware, build the client with the request/response cookie adapter and `await supabase.auth.getUser()` on every request, before returning the response.",
  "docsUrl": "https://pitcheye.dev/rules/supabase-auth-missing-session-refresh-middleware"
}

Markdown: curl -H "Accept: text/markdown" https://pitcheye.dev/rules/supabase-auth-missing-session-refresh-middleware

raw markdown
# supabase-auth/missing-session-refresh-middleware

- **severity:** warn
- **pack:** supabase-auth
- **docs:** https://pitcheye.dev/rules/supabase-auth-missing-session-refresh-middleware

## whyItBreaks

With @supabase/ssr the access token lives ~1h and is refreshed by the middleware. Without the refresh the session expires mid-visit and every server component starts rendering as signed-out — the classic "randomly logged out" report that is impossible to reproduce locally.

## bad

```ts
export function middleware(req: NextRequest) {
  return NextResponse.next();
}
```

## good

```ts
export async function middleware(req: NextRequest) {
  const supabase = createServerClient(url, key, { cookies: adapter });
  await supabase.auth.getUser();
  return response;
}
```

## suggestedFix

In middleware, build the client with the request/response cookie adapter and `await supabase.auth.getUser()` on every request, before returning the response.

## commands

```bash
npx @pitcheye/check . --pack supabase-auth
```

```json
{"tool":"explain_rule","arguments":{"ruleId":"supabase-auth/missing-session-refresh-middleware"}}
```
← supabase-auth/service-role-in-clientBack to rule catalogsupabase-auth/sync-cookies-next15 →