How to detect code is running under v0

I tried looking in the documentation but can’t seem to find it.

I want to disable some code when running under v0, initially the workos integration, but there may be others later on.
I trued setting an environment variable USING_V0=true inside of v0, but then it was added to my vercel project.

I’m at a loss at what I can do, I’d like to keep the environment of the vercel project separate, or at least is there a way to tell the code is under v0, and I can check that instead of using my hacky environment variable.

Here’s what I’m doing now (in one of a few places) - any advice is appreciated. Thanks!!

const isV0Preview = process.env.USING_V0 === "true"
const hasWorkOSConfig = process.env.WORKOS_CLIENT_ID && process.env.WORKOS_API_KEY && process.env.WORKOS_COOKIE_PASSWORD
// Skip authentication in v0 preview or when WorkOS is not configured
if (isV0Preview || !hasWorkOSConfig) {
  console.log("[v0] Skipping WorkOS auth middleware - not configured")
  return NextResponse.next()
}

There’s no environment variable to detect v0 at the moment and no official way to do this

However currently you can check if the window hostname includes the preview iframe URL. There are no guarantees this will work forever though

const isV0 = window.location.hostname.includes("vusercontent.net")

Thanks Jacob!

I was just coding up something similiar after looking at all of the environment variables on my local machine running the code under vscode, on v0 and also on a production deployment on vercel. Since I need this on server side, I went with this, let me know any obvious flaws (apart from your comment that vusercontent.net may not last forever). I was also thinking the VERCEL_PROJECT_ID is empty on v0 and may be a good check instead.

function isV0() {
  const is_vercel = process.env.VERCEL == "1"
  const vercel_url = process.env.VERCEL_URL || "myapp"
  return is_vercel && vercel_url.endsWith(".vusercontent.net")
}