convex-setup-auth by get-convex/agent-skills
npx skills add https://github.com/get-convex/agent-skills --skill convex-setup-auth在 Convex 中实现安全的认证,包括用户管理和访问控制。
Convex 支持多种认证方法。不要假设使用某个提供商。
在编写设置代码之前:
常见选项:
在询问之前,先在仓库中寻找线索:
@clerk/*、、 或 Convex Auth 包广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
@workos-inc/*@auth0/*convex/auth.config.ts、认证中间件、提供商包装器或登录组件阅读该提供商的官方指南和匹配的本地参考文件:
本地参考文件包含具体的工作流程、预期的文件和环境变量、注意事项以及验证检查。
使用这些来源处理:
convex/auth.config.ts 设置对于共享的认证行为,请使用官方 Convex 文档作为权威来源:
ctx.auth.getUserIdentity()优先使用官方文档而非记忆中的步骤,因为提供商 CLI 和 Convex Auth 内部实现在不同版本之间会发生变化。凭记忆创建设置可能导致使用过时的模式。对于第三方提供商,只有在应用确实需要在 Convex 中存储用户文档时才添加应用程序级用户存储。并非每个应用都需要 users 表。对于 Convex Auth,请遵循 Convex Auth 文档和内置的认证表,而不是添加一个并行的 users 表和 storeUser 流程,因为 Convex Auth 已经在内部管理用户记录。运行提供商初始化命令后,请验证生成的文件并完成提供商参考指出的初始化后配置步骤。初始化命令很少能完成整个集成。
最常见的认证任务是在 Convex 函数中检查身份。
// 错误:信任客户端提供的 userId
export const getMyProfile = query({
args: { userId: v.id("users") },
handler: async (ctx, args) => {
return await ctx.db.get(args.userId);
},
});
// 正确:在服务端验证身份
export const getMyProfile = query({
args: {},
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Not authenticated");
return await ctx.db
.query("users")
.withIndex("by_tokenIdentifier", (q) =>
q.eq("tokenIdentifier", identity.tokenIdentifier)
)
.unique();
},
});
如果流程因交互式提供商或部署设置而阻塞,请明确询问用户需要的确切人工步骤,然后在他们完成后继续。对于面向 UI 的认证流程,在设置完成后主动验证真实的注册或登录流程。如果环境中有浏览器自动化工具,可以使用它们。如果没有,则给用户一个简短的手动验证清单。
references/convex-auth.mdreferences/clerk.mdreferences/workos-authkit.mdreferences/auth0.mdusers 表或 storeUser 流程每周安装量
6.8K
仓库
GitHub 星标数
15
首次出现
10 天前
安全审计
安装于
codex6.8K
cursor6.8K
kimi-cli6.8K
amp6.8K
github-copilot6.8K
cline6.8K
Implement secure authentication in Convex with user management and access control.
Convex supports multiple authentication approaches. Do not assume a provider.
Before writing setup code:
Common options:
Look for signals in the repo before asking:
@clerk/*, @workos-inc/*, @auth0/*, or Convex Auth packagesconvex/auth.config.ts, auth middleware, provider wrappers, or login componentsRead the provider's official guide and the matching local reference file:
references/convex-auth.mdreferences/clerk.mdreferences/workos-authkit.mdreferences/auth0.mdThe local reference files contain the concrete workflow, expected files and env vars, gotchas, and validation checks.
Use those sources for:
convex/auth.config.ts setupFor shared auth behavior, use the official Convex docs as the source of truth:
ctx.auth.getUserIdentity()Prefer official docs over recalled steps, because provider CLIs and Convex Auth internals change between versions. Inventing setup from memory risks outdated patterns. For third-party providers, only add app-level user storage if the app actually needs user documents in Convex. Not every app needs a users table. For Convex Auth, follow the Convex Auth docs and built-in auth tables rather than adding a parallel users table plus storeUser flow, because Convex Auth already manages user records internally. After running provider initialization commands, verify generated files and complete the post-init wiring steps the provider reference calls out. Initialization commands rarely finish the entire integration.
The most common auth task is checking identity in Convex functions.
// Bad: trusting a client-provided userId
export const getMyProfile = query({
args: { userId: v.id("users") },
handler: async (ctx, args) => {
return await ctx.db.get(args.userId);
},
});
// Good: verifying identity server-side
export const getMyProfile = query({
args: {},
handler: async (ctx) => {
const identity = await ctx.auth.getUserIdentity();
if (!identity) throw new Error("Not authenticated");
return await ctx.db
.query("users")
.withIndex("by_tokenIdentifier", (q) =>
q.eq("tokenIdentifier", identity.tokenIdentifier)
)
.unique();
},
});
If the flow blocks on interactive provider or deployment setup, ask the user explicitly for the exact human step needed, then continue after they complete it. For UI-facing auth flows, offer to validate the real sign-up or sign-in flow after setup is done. If the environment has browser automation tools, you can use them. If it does not, give the user a short manual validation checklist instead.
references/convex-auth.mdreferences/clerk.mdreferences/workos-authkit.mdreferences/auth0.mdusers table or storeUser flow for Convex AuthWeekly Installs
6.8K
Repository
GitHub Stars
15
First Seen
10 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex6.8K
cursor6.8K
kimi-cli6.8K
amp6.8K
github-copilot6.8K
cline6.8K
99,500 周安装