convex-auth
Skill17 starsChanged 10 months agoMITView on GitHub
Core authentication patterns for Convex backends. Use when implementing auth checks in functions, storing users in database, creating auth helpers, or debugging auth issues. Works with any auth provider (Clerk, WorkOS, Auth0, etc.).
8 other projects use a version of this.
Adopted by
Most recently taken up by
- alibey-10/defttheir own version, first seen Nov 29, 2026
- get-convex/agent-skillstheir own version, first seen Oct 29, 2026
- convex/agent-skillstheir own version, first seen Oct 17, 2026
- moltbot/molthubtheir own version, first seen Oct 8, 2026
- clawdbot/clawdhubtheir own version, first seen Oct 8, 2026
- openclaw/clawhubtheir own version, first seen Oct 8, 2026
Used with
Projects with it also use convex-acquire-domain, convex-check-updates and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
FabienGreardSkillconvex-acquire-domain
Find and buy a domain for the current Convex app through Convex, then bind it (labs; spend action).
Also in 4 projects that use this
FabienGreardSkillconvex-check-updates
Check the current app's pinned Convex components against recommended versions and upgrade them behind a build gate.
Also in 4 projects that use this
openclawSkillclawhub-ban-appeals
Review ClawHub account-ban appeals, distinguish bans from moderation holds or blocked releases, and prepare an evidence-backed moderation decision. Route validated scanner inaccuracies to clawhub-clawscan.
Also in 3 projects that use this
openclawSkillclawhub-clawscan
Investigate ClawScan health alerts, diagnose scanner or ClawHub integration failures, prepare operational repairs, and route validated verdict inaccuracies upstream. Account ban appeals use clawhub-ban-appeals.
Also in 3 projects that use this
- +8 more from openclaw
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- clawdbot/clawdhub★ 9.6ksame name
- moltbot/molthub★ 9.6ksame name
- openclaw/clawhub★ 9.6ksame name
- convex/agent-skills★ 69same name
- get-convex/agent-skills★ 69same name
- alibey-10/deft★ 24same name
- FabienGreard/TouchGrassBar★ 6same name
- getsentry/friday★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- convex-agentSkill
- convex-clerkSkill
- convex-componentsSkill
- convexSkill
- convex-workosSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. 0 are common, 1 is distinctive, and 13 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
13
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 46
Client-side: Always use useConvexAuth() from convex/react, NOT your provider's hook:
- Very specific: line 87
Create authenticated function wrappers using convex-helpers:
- Very specific: line 183
Check if query runs before auth completes (use "skip" pattern)
- Very specific: line 184
Check auth.config.ts is deployed (npx convex dev)
- Distinctive: line 185
Check Settings > Authentication in Convex Dashboard
- Very specific: line 186
Verify JWT token at https://jwt.io - check iss and aud fields
- Very specific: line 187
Ensure domain in auth.config.ts matches JWT iss
- Very specific: line 188
Ensure applicationID matches JWT aud
- Very specific: line 192
Always check ctx.auth.getUserIdentity() in public functions
- Very specific: line 193
Use useConvexAuth() hook, not provider's auth hook
- Very specific: line 195
Use <Authenticated> component to gate protected content
- Very specific: line 197
Use tokenIdentifier or subject as unique user key
- Very specific: line 202
Run queries before checking isAuthenticated
- Very specific: line 203
Use .filter() to find users by token (use index)
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Convex Authentication - Core Patterns
This skill covers universal auth patterns that work with ANY authentication provider.
Auth in Functions
Access the authenticated user via ctx.auth.getUserIdentity():
import { query, mutation, action } from './_generated/server';
export const myQuery = query({
args: {},
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
if (identity === null) {
throw new Error('Not authenticated');
}
// identity.tokenIdentifier - unique across providers
// identity.subject - user ID from provider
// identity.email, identity.name, etc. (if configured)
}
});UserIdentity Fields
| Field | Guaranteed | Description |
tokenIdentifier | ✅ | Unique ID (subject + issuer combined) |
subject | ✅ | User ID from auth provider |
issuer | ✅ | Auth provider domain |
email | Provider-dependent | User's email |
name | Provider-dependent | Display name |
pictureUrl | Provider-dependent | Avatar URL |
Critical: Race Condition Prevention
Problem: Queries can execute before auth is validated on page load.
Client-side: Always use useConvexAuth() from convex/react, NOT your provider's hook:
// ✅ Correct - waits for Convex to validate token
import { useConvexAuth } from 'convex/react';
const { isLoading, isAuthenticated } = useConvexAuth();
// ❌ Wrong - only checks provider, not Convex validation
const { isSignedIn } = useAuth(); // from @clerk/clerk-reactSkip queries until authenticated:
const user = useQuery(api.users.current, isAuthenticated ? {} : 'skip');Use Convex auth components:
import { Authenticated, Unauthenticated, AuthLoading } from "convex/react";
<Authenticated>
<Content /> {/* Queries here are safe */}
</Authenticated>
<Unauthenticated>
<SignInButton />
</Unauthenticated>Storing Users in Database
See USERS.md for complete patterns including:
- Schema design with indexes
- Storing users via client mutation
- Storing users via webhooks (recommended for production)
- Helper functions for user lookup
Custom Auth Wrappers
Create authenticated function wrappers using convex-helpers:
// convex/lib/auth.ts
import {
query,
mutation,
action,
QueryCtx,
MutationCtx,
ActionCtx
} from './_generated/server';
import {
customQuery,
customMutation,
customAction,
customCtx
} from 'convex-helpers/server/customFunctions';
import { ConvexError } from 'convex/values';
async function requireAuth(ctx: QueryCtx | MutationCtx | ActionCtx) {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
throw new ConvexError('Not authenticated');
}
return identity;
}
export const authQuery = customQuery(
query,
customCtx(async (ctx) => {
const identity = await requireAuth(ctx);
return { identity };
})
);
export const authMutation = customMutation(
mutation,
customCtx(async (ctx) => {
const identity = await requireAuth(ctx);
return { identity };
})
);
export const authAction = customAction(
action,
customCtx(async (ctx) => {
const identity = await requireAuth(ctx);
return { identity };
})
);Usage:
import { authQuery } from './lib/auth';
export const myProtectedQuery = authQuery({
args: {},
handler: async (ctx) => {
// ctx.identity is guaranteed to exist
const userId = ctx.identity.subject;
}
});HTTP Actions with Auth
Pass JWT in Authorization header:
// Client
fetch('https://your-deployment.convex.site/api/endpoint', {
headers: { Authorization: `Bearer ${jwtToken}` }
});
// convex/http.ts
import { httpAction } from './_generated/server';
export const myEndpoint = httpAction(async (ctx, request) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) {
return new Response('Unauthorized', { status: 401 });
}
// ...
});Debugging Checklist
See DEBUG.md for detailed troubleshooting steps.
Quick checks:
ctx.auth.getUserIdentity()returnsnull?- Check if query runs before auth completes (use
"skip"pattern) - Check auth.config.ts is deployed (
npx convex dev)
- Check if query runs before auth completes (use
- Check Settings > Authentication in Convex Dashboard
- Verify JWT token at https://jwt.io - check
issandaudfields - Ensure
domainin auth.config.ts matches JWTiss - Ensure
applicationIDmatches JWTaud
DO ✅
- Always check
ctx.auth.getUserIdentity()in public functions - Use
useConvexAuth()hook, not provider's auth hook - Skip queries with
"skip"until authenticated - Use
<Authenticated>component to gate protected content - Store users in DB for cross-user queries
- Use
tokenIdentifierorsubjectas unique user key
DON'T ❌
- Trust client-side auth alone (Convex is a public API)
- Run queries before checking
isAuthenticated - Use
.filter()to find users by token (use index) - Assume identity fields exist (check provider config)
- Forget to redeploy after changing auth.config.ts
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

