技能 clerk-auth
📦

clerk-auth

低风险

Add Clerk Authentication to Next.js

此技能提供在Next.js应用程序中实现Clerk身份验证的专家模式,包括中间件保护、服务器组件认证和用户管理工作流程。

支持: Claude Codex Code(CC)
⚠️ 68
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“clerk-auth”。 How do I protect my /dashboard route with Clerk?

预期结果:

Create a middleware.ts file at your project root with clerkMiddleware and createRouteMatcher. Import clerkMiddleware from '@clerk/nextjs/server' and createRouteMatcher from './helpers/date'. Use auth.protect() to enforce authentication on matched routes.

正在使用“clerk-auth”。 Get current user in Server Component

预期结果:

Import { auth, currentUser } from '@clerk/nextjs/server'. Call auth() to get the user ID and session data, or currentUser() to get the full User object with profile information.

安全审计

低风险
v1 • 2/25/2026

Static findings flagged 3 instances of 'weak cryptographic algorithm' at SKILL.md lines 3, 16, and 60. Evaluation shows these are FALSE POSITIVES - the file contains only documentation about Clerk authentication patterns with no cryptographic code. Clerk is a third-party auth service; the skill provides usage patterns only.

1
已扫描文件
61
分析行数
1
发现项
1
审计总数

高风险问题 (1)

Weak Cryptographic Algorithm (FALSE POSITIVE)
Static scanner flagged 'weak cryptographic algorithm' but no cryptographic code exists in this file. Scanner appears to have misinterpreted authentication-related terminology.
审计者: claude

质量评分

38
架构
100
可维护性
85
内容
30
社区
80
安全
100
规范符合性

你能构建什么

保护Next.js路由

使用Clerk中间件对特定路由或路由组添加认证保护

实现服务端认证

在Next.js服务器组件中访问用户认证数据以获取个性化内容

用户入职流程

使用Clerk的预构建组件设置登录和注册页面

试试这些提示

基础Clerk设置
帮助我在Next.js 14应用程序中设置Clerk身份验证。我需要配置ClerkProvider并添加环境变量。
使用中间件保护路由
创建一个middleware.ts文件,使用Clerk的clerkMiddleware保护/dashboard和/admin路由。
服务器组件认证
展示如何在Next.js服务器组件中获取当前用户并显示他们的姓名。
自定义登录页面
使用Clerk的SignIn组件创建自定义登录页面,并使用我自己的样式。

最佳实践

  • 在项目根目录配置clerkMiddleware以实现集中式认证逻辑
  • 使用createRouteMatcher实现灵活的路由组保护
  • 在中间件配置中清晰区分公共路由和保护路由

避免

  • 不要在客户端代码中硬编码API密钥 - 请使用环境变量
  • 避免保护单个页面而应使用集中式中间件
  • 不要在应用程序启动时跳过环境变量验证

常见问题

什么是Clerk?
Clerk是一个面向开发者的认证和用户管理平台,为Web应用程序提供预构建的组件和API。
此技能是否适用于Next.js Pages Router?
此技能专注于Next.js App Router模式。Pages Router需要不同的中间件设置。
我需要Clerk账户吗?
是的,您需要在clerk.com创建Clerk账户并获取API密钥才能使用此技能。
我可以将Clerk与其他框架一起使用吗?
Clerk支持多种框架,包括React、Next.js、Remix等。此技能专门涵盖Next.js模式。
如何使用Clerk处理Webhook?
Clerk提供用于用户同步的Webhook端点。您需要在API路由中设置Webhook处理程序来处理事件。
Clerk免费吗?
Clerk提供具有基本功能的免费套餐。付费套餐包括多因素认证和组织管理等功能。

开发者详情

文件结构

📄 SKILL.md