clerk-auth-check

A coding rule for React components that use Convex, a backend platform, with Clerk, an authentication service. It checks that admin-only data requests wait until authentication has finished and the user is signed in.

In plain words
What is it for?
Use it when reviewing React components that call admin-protected Convex queries or paginated queries.
Why use it?
It helps prevent protected queries from running too early or for unauthenticated users, avoiding loading and access errors.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/waynesutton/promptstack/clerk-auth-check
Clone the repo
git clone --depth 1 https://github.com/waynesutton/promptstack

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 642 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00642
Opus 5 $0.00000 $0.00321
Sonnet 5 $0.00000 $0.00128
Haiku 4.5 $0.00000 $0.00064

Measured 2d ago against content hash 7524c0c0d45d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

clerk-auth-check scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/clerk-auth-check.mdc · 61 lines

What it actually says

This rule helps ensure that React components using Convex queries with Clerk authentication correctly handle loading and authentication states before attempting to fetch data, especially for admin-protected queries.

name: convex-clerk-admin-auth-guard
description: Ensures React components correctly handle auth state before calling admin-protected Convex queries.
globs: src/**/*.{ts,tsx}
condition: |
  // Heuristic: Component uses useQuery/usePaginatedQuery for an "admin" query
  // AND does NOT seem to have robust useConvexAuth handling for skipping.
  // This is a simplified check; real implementation might need more sophisticated AST parsing.
  const fileContent = ctx.currentFile.content;
  const usesAdminQuery = /use(Query|PaginatedQuery)\\s*\\(\\s*api\\.\\w+\\.\\w+Admin/.test(fileContent);
  const usesConvexAuth = /useConvexAuth\\s*\\(\s*\\)/.test(fileContent);
  const hasSkipLogic = /authIsLoading\\s*\\|\\|\\s*!isAuthenticated\\s*\\?\\s*\"skip\"/.test(fileContent);

  if (usesAdminQuery && (!usesConvexAuth || !hasSkipLogic)) {
    return true; // Condition met to offer advice
  }
  return false;
advice: |
  When using Convex queries that require admin authentication (often named like `...Admin`) with Clerk, ensure your React component correctly handles authentication states to prevent errors:

  1.  **Use `useConvexAuth`**: Get `authIsLoading` and `isAuthenticated`.
      ```tsx
      import { useConvexAuth } from "convex/react";
      // ...
      const { isLoading: authIsLoading, isAuthenticated } = useConvexAuth();
      ```

  2.  **Handle Auth Loading**: Display a loading message if `authIsLoading` is true.
      ```tsx
      if (authIsLoading) {
        return <div>Loading authentication...</div>;
      }
      ```

  3.  **Handle Not Authenticated**: (Optional, but good for UX if routing doesn't cover it)
      If not `authIsLoading` and not `isAuthenticated`, prompt for login.
      ```tsx
      if (!isAuthenticated) {
        return <div>Please log in to access this section.</div>;
      }
      ```

  4.  **Conditionally Skip Queries**: Pass `"skip"` to `useQuery` or `usePaginatedQuery` if `authIsLoading` or `!isAuthenticated`.
      ```tsx
      const adminData = useQuery(
        api.yourModule.yourAdminQuery,
        (authIsLoading || !isAuthenticated) ? "skip" : { /* your_args */ }
      );
      ```
  This prevents queries from running before authentication is resolved, avoiding "No identity found" errors from `requireAdminRole` in your Convex functions.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 61 lines · 0 tokens per session scan A 7524c0c0d45d

Subscribe to this mod's changes

clerk-auth-check is a cursor rule published in the GitHub repository waynesutton/promptstack (76 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 642 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.