CL

clerk-local-dev-loop

Local environment setup for Clerk, including mock user seeding and development instance isolation.

Install

mkdir -p .claude/skills/clerk-local-dev-loop && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/4810" && unzip -o skill.zip -d .claude/skills/clerk-local-dev-loop && rm skill.zip

Installs to .claude/skills/clerk-local-dev-loop

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Set up local development workflow with Clerk.
45 charsno explicit “when” trigger
Intermediate

Key capabilities

  • Configure Clerk development instances with test keys
  • Automate user seeding for local development environments
  • Enable HTTPS for local development servers
  • Implement authentication mocks for Vitest unit tests
  • Create Playwright fixtures for end-to-end testing

How it works

The tool provides scripts and configuration patterns to isolate development auth data using test keys and local seeding utilities. It also includes mock helpers to bypass live authentication during unit and end-to-end testing.

Inputs & outputs

You give it
Clerk test keys and user data definitions
You get back
Configured development environment with seeded users and mock auth helpers

When to use clerk-local-dev-loop

  • Configure local development environment
  • Test authentication flows locally
  • Seed test users for development
  • Set up Clerk for hot reloading workflows

About this skill

Clerk Local Dev Loop

Overview

Configure an efficient local development workflow with Clerk authentication, including test users, hot reload, and mock auth for unit tests.

Prerequisites

  • Clerk SDK installed (clerk-install-auth completed)
  • Development instance created in Clerk Dashboard
  • Node.js development environment

Instructions

Step 1: Configure Development Instance

Create a separate Clerk development instance to isolate test data from production.

# .env.local — use test keys (pk_test_ / sk_test_)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...

# Optional: Enable Clerk debug logging
CLERK_DEBUG=true

Clerk development instances provide:

  • No email verification required
  • Test phone numbers accepted
  • Relaxed rate limits
  • OAuth with test credentials

Step 2: Set Up Test Users

// scripts/seed-test-users.ts
import { createClerkClient } from '@clerk/backend'

const clerk = createClerkClient({ secretKey: process.env.CLERK_SECRET_KEY! })

async function seedTestUsers() {
  const users = [
    { emailAddress: ['[email protected]'], password: 'test1234', firstName: 'Admin', lastName: 'User' },
    { emailAddress: ['[email protected]'], password: 'test1234', firstName: 'Member', lastName: 'User' },
  ]

  for (const user of users) {
    try {
      await clerk.users.createUser(user)
      console.log(`Created: ${user.emailAddress[0]}`)
    } catch (err: any) {
      if (err.status === 422) {
        console.log(`Already exists: ${user.emailAddress[0]}`)
      } else {
        throw err
      }
    }
  }
}

seedTestUsers()

Run with:

npx tsx scripts/seed-test-users.ts

Step 3: Configure Hot Reload

// next.config.ts — ensure Clerk works with hot reload
const nextConfig = {
  // Clerk SDK is compatible with Turbopack
  experimental: {
    // turbo: {}, // Uncomment if using Turbopack
  },
  // Prevent Clerk SDK from being bundled incorrectly
  serverExternalPackages: ['@clerk/backend'],
}

export default nextConfig
# Start dev server with HTTPS (required for some Clerk features)
npx next dev --experimental-https

Step 4: Development Scripts

// package.json scripts
{
  "scripts": {
    "dev": "next dev",
    "dev:https": "next dev --experimental-https",
    "dev:seed": "tsx scripts/seed-test-users.ts",
    "dev:tunnel": "ngrok http 3000",
    "dev:webhook": "ngrok http 3000 --log stdout"
  }
}

Step 5: Mock Authentication for Tests

// test/helpers/clerk-mock.ts
import { vi } from 'vitest'

export function mockClerkAuth(overrides: { userId?: string; orgId?: string } = {}) {
  const mockAuth = {
    userId: overrides.userId || 'user_test_123',
    orgId: overrides.orgId || null,
    getToken: vi.fn().mockResolvedValue('mock_token'),
    has: vi.fn().mockReturnValue(true),
  }

  vi.mock('@clerk/nextjs/server', () => ({
    auth: vi.fn().mockResolvedValue(mockAuth),
    currentUser: vi.fn().mockResolvedValue({
      id: mockAuth.userId,
      firstName: 'Test',
      lastName: 'User',
      emailAddresses: [{ emailAddress: '[email protected]' }],
    }),
    clerkMiddleware: vi.fn(() => (req: any, res: any, next: any) => next()),
  }))

  return mockAuth
}
// test/api/data.test.ts
import { describe, it, expect, beforeEach } from 'vitest'
import { mockClerkAuth } from '../helpers/clerk-mock'

describe('GET /api/data', () => {
  beforeEach(() => {
    mockClerkAuth({ userId: 'user_test_123' })
  })

  it('returns data for authenticated user', async () => {
    const res = await fetch('/api/data')
    expect(res.status).toBe(200)
  })
})

Output

  • Development instance with test keys configured
  • Test users seeded via script
  • HTTPS dev server running for Clerk compatibility
  • Vitest mock helpers for auth in unit tests

Error Handling

ErrorCauseSolution
Dev/prod key mismatchUsing pk_live_ in devSwitch to pk_test_ / sk_test_ keys
SSL requiredClerk needs HTTPS locallyRun next dev --experimental-https
Cookies not setWrong domain configCheck Clerk Dashboard domain settings
Session not persistingBrowser storage issueClear cookies, check localhost domain

Examples

Playwright Auth Fixture for E2E Tests

// e2e/fixtures/auth.ts
import { test as base } from '@playwright/test'

export const test = base.extend({
  authenticatedPage: async ({ page }, use) => {
    await page.goto('/sign-in')
    await page.fill('input[name="identifier"]', '[email protected]')
    await page.click('button:has-text("Continue")')
    await page.fill('input[name="password"]', 'test1234')
    await page.click('button:has-text("Continue")')
    await page.waitForURL('/dashboard')
    await use(page)
  },
})

Resources

Next Steps

Proceed to clerk-sdk-patterns for common SDK usage patterns.

When not to use it

  • Production environments using live keys
  • Environments without Node.js installed

Prerequisites

Clerk SDK installedDevelopment instance created in Clerk DashboardNode.js development environment

Limitations

  • Requires HTTPS for specific local Clerk features
  • Requires manual domain configuration in Clerk Dashboard for session persistence

How it compares

This workflow automates the setup of isolated test instances and mock helpers rather than manually configuring auth state for every local test run.

Compared to similar skills

clerk-local-dev-loop side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
clerk-local-dev-loop (this skill)125dReviewIntermediate
clerk-hello-world125dReviewBeginner
clerk-ci-integration025dReviewAdvanced
browser-auth02moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

Search skills

Search the agent skills registry