#How i run Clerk on Preview Deployment since all keys get erased on branch deploy?

5 messages · Page 1 of 1 (latest)

blazing oar
#

How i run Clerk on Preview Deployment since all keys get erased on branch deploy?

weak dustBOT
#

Hi @blazing oar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

When using Convex preview deployments (e.g., with Vercel or Netlify), each new preview deployment is a fresh backend, and any environment variables set directly on the deployment (not as defaults) are wiped out on each new deploy. This includes your Clerk keys and issuer domains, which are required for authentication to work.

How to persist Clerk keys and issuer domains for preview deployments:

  1. Use Project Environment Variable Defaults:
    Convex supports setting default environment variables for all new preview (and dev) deployments. This ensures that every new preview deployment automatically gets the necessary Clerk configuration (like CLERK_JWT_ISSUER_DOMAIN, CLERK_FRONTEND_API_URL, and Clerk API keys) without having to manually set them each time.
    You can configure these defaults in the Convex dashboard under your project’s environment variable settings. This is the recommended way to ensure your Clerk integration works seamlessly across all preview deployments, as the defaults are automatically applied to every new preview deployment and are not wiped out on redeploys.
    See more here and as mentioned by support staff in Discord:

    "I believe the closest solution is using default environment variables, which apply to all new preview deployments, but also to all new dev deployments."
    Discord thread

#
  1. Set Up Clerk for Each Environment:
    Make sure you set the correct Clerk keys and issuer domains for each environment (dev, prod, preview) using these defaults. For example, set CLERK_FRONTEND_API_URL and NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY as defaults for preview deployments in the Convex dashboard.
    See Clerk/Convex environment variable setup.

Summary:
To run Clerk on Convex preview deployments and avoid losing your keys on each branch deploy, set your Clerk-related environment variables as project environment variable defaults in the Convex dashboard. This will ensure they are automatically present in every new preview deployment.

If you need more details on how to set these up, refer to the Convex environment variable defaults documentation.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@blazing oar Kapa.ai is still learning and improving, please let me know how I did by reacting below.