clerk-security-basics

Featured

Implement security best practices with Clerk authentication. Use when securing your application, reviewing auth implementation, or hardening Clerk configuration. Trigger with phrases like "clerk security", "secure clerk", "clerk best practices", "clerk hardening".

AI & Automation 2,944 stars 440 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Clerk Security Basics ## Overview Implement security best practices for Clerk authentication: environment variable protection, middleware hardening, API route defense, webhook verification, and session security. ## Prerequisites - Clerk SDK installed and configured - Understanding of OWASP authentication best practices - Production deployment planned or active ## Instructions ### Step 1: Secure Environment Variables ```bash # .env.local — never commit this file NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_... # Safe to expose (public) CLERK_SECRET_KEY=sk_live_... # NEVER expose client-side CLERK_WEBHOOK_SECRET=whsec_... # Server-only ``` ```gitignore # .gitignore — ensure secrets stay out of git .env.local .env.*.local .env.production ``` Validate at startup that secret keys are not leaked: ```typescript // lib/security-check.ts export function assertServerOnly() { if (typeof window !== 'undefined') { throw new Error('This module must only be used server-side') } if (!process.env.CLERK_SECRET_KEY) { throw new Error('CLERK_SECRET_KEY is not configured') } } ``` ### Step 2: Hardened Middleware Configuration ```typescript // middleware.ts import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server' import { NextResponse } from 'next/server' const isPublicRoute = createRouteMatcher([ '/', '/sign-in(.*)', '/sign-up(.*)', '/api/webhooks(.*)', ]) export default clerkMiddleware(async (auth, req) => { ...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category