Skip to content

@clerk/testing: clerkSetup() doesn't fall back to NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY #7892

@joerizz23

Description

@joerizz23

Description

clerkSetup() from @clerk/testing/playwright requires the env var CLERK_PUBLISHABLE_KEY to be set. However, the standard Next.js convention (and what @clerk/nextjs uses) is NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY. This forces developers to pass both env vars explicitly when running tests.

Environment

  • @clerk/testing: 1.13.36
  • @clerk/nextjs: latest
  • @playwright/test: 1.57.0
  • Next.js: 15.4.11

Reproduction

  1. Configure a Next.js app with Clerk using NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY in .env.local (standard setup)
  2. Set up Playwright with @clerk/testing
  3. Run tests without explicitly setting CLERK_PUBLISHABLE_KEY
  4. clerkSetup() fails because it only looks for CLERK_PUBLISHABLE_KEY

Workaround

Must pass both env vars when running tests:

CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY \
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxx \
npx playwright test

Expected Behavior

clerkSetup() should fall back to NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY if CLERK_PUBLISHABLE_KEY is not set, since that's the standard env var name used in Next.js projects with @clerk/nextjs.

Suggested Fix

In the clerkSetup() initialization:

const publishableKey = process.env.CLERK_PUBLISHABLE_KEY 
  ?? process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions