grezxune/ai-tools/convex
Claude Code and agent skill by grezxune/ai-tools
- community
Checking that the SKILL.md file is still in the repository.
Convex patterns for schema, queries, mutations, and auth. Use before writing or reviewing Convex code in a repo with no `docs/convex.md`.
Install
npx vskill@latest install grezxune/ai-tools/convexSKILL.md
The same SKILL.md was published earlier as grezxune/ai-tools/convex.
Convex Patterns
Read this before writing or reviewing Convex schema, queries, mutations, actions, or auth.
Auth Setup
Better Auth runs inside Convex through the @convex-dev/better-auth component. Follow the component's Next.js guide (https://labs.convex.dev/better-auth/framework-guides/next) for the files, with these rules on top:
- Pin
better-authto the range in the component'speerDependencies. Component 0.12 needsbetter-auth1.6.x, and its guide pins~1.6.15. - The auth instance runs in Convex, so
BETTER_AUTH_SECRET,SITE_URL, and OAuth credentials such asGOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETare Convex environment variables, set withnpx convex env setor the dashboard..env.localholds onlyCONVEX_DEPLOYMENT,NEXT_PUBLIC_CONVEX_URL,NEXT_PUBLIC_CONVEX_SITE_URL(the.convex.siteaddress), andNEXT_PUBLIC_SITE_URL. - Google's authorized redirect URI is
<SITE_URL>/api/auth/callback/google. Next.js serves/api/auth/*and forwards it to Convex. - Better Auth's tables (
user,session,account) live in the component, outside the app schema. The app keeps its ownuserstable, linked byauthId(next section).
User IDs & Data Ownership
- Every person has a row in the app's
userstable withauthId: v.string(), the Better Auth user's_id, and aby_authIdindex. Auser.onCreatetrigger creates the row in the same transaction as the Better Auth user.onUpdatecopies a changed email or name, andonDeleteremoves the row, or marks it deleted while other tables still point at it. - Use
userId: v.id("users")as the ownership field on every user-owned table. - Never use email as a foreign key. Email lives only on the
userstable, copied there by the trigger. - Never join or filter across tables by email. Use
userId. - Every table with a
userIdfield needs aby_userIdindex. - Use compound indexes for common filters, e.g.
by_userId_status. - The
by_authIdindex exists only forgetAuthUser(), which turns the session into the app user. After that, useuser._id.
Authorization (non-negotiable)
Never trust client-supplied userId, email, role, or platformRole for authorization.
Identity comes from the session, checked inside Convex:
authComponent.safeGetAuthUser(ctx)returns the Better Auth user when the session exists and has not expired, andundefinedotherwise.authComponent.getAuthUser(ctx)throwsConvexError("Unauthenticated")instead.ctx.auth.getUserIdentity()reads the JWT only. A signed-out or revoked session keeps a valid JWT until it expires, so reach identity through the helpers inconvex/lib/auth.ts, which go throughsafeGetAuthUser.
Every public Convex query/mutation that accepts userId must:
- Resolve the actor with
requireAuthenticatedUserId(ctx, args.userId), which maps the session to the app user and rejects a mismatch. - Enforce ownership and role checks in Convex against stored records.
Deny by default: missing auth, missing ownership, or identity mismatch fails immediately. No deterministic or default secret/key fallbacks in production. Development-only auth providers must be disabled in production builds.
Enforcement Pattern
- Do not use raw
query/mutationfor protected operations. Use shared wrappers:authenticatedQuery,authenticatedMutation,superAdmin*. - Admin operations enforce role checks inside Convex, not only in Next.js pages or server actions.
- Server components and server actions call Convex through
fetchAuthQuery,fetchAuthMutation,fetchAuthAction, andpreloadAuthQueryfromsrc/lib/auth-server.ts, which carry the session's token. The Convex function still runs its own checks. - Prefer
internalQuery/internalMutationfor server-to-server work.
File Organization
Reference internal functions as internal.{domain}.internalQueries.fn, not .queries..
Auth Utilities (convex/lib/auth.ts)
Every helper builds on getAuthUser(), the one place a session becomes an app user:
Frontend Hook (src/hooks/use-auth-user.ts)
Gate on Convex's auth state: <Authenticated>, <Unauthenticated>, <AuthLoading>, or useConvexAuth(). Better Auth's useSession() can report a signed-in user before Convex has the token, and an authenticated query run then throws.
Server-Side Filtering
Every list the UI shows comes from a query that already applied the view's filters. The component renders what it receives.
- Put each filter the view uses (status, date range, parent id, search text) in the query's
argsand apply it in the handler. - Apply filters with
.withIndex(). A.collect()followed by a JS.filter()still reads every row, even on the server. - Run text search through a search index with
.withSearchIndex(). - Use
.paginate()withusePaginatedQueryfor any list that grows with usage. Keep.collect()for small, bounded sets. - Map documents to the fields the view renders before returning. Other users' emails, internal flags, and tokens stay on the server.
- When a view needs a different subset, write a query for that subset rather than reusing a broader one.
Query & Mutation Shape
Required Security Tests
One negative authorization test per sensitive domain:
- Mismatched
userIdis rejected. - Unauthenticated call is rejected.
- Non-admin actor cannot reach admin-only paths.
- An identity whose session was signed out or expired is rejected.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/convex/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/grezxune/ai-tools/convex)