Kinde and edge worker services
Integrations
Cloudflare Workers provide a serverless edge runtime for deploying Next.js applications. This guide covers the specific configuration required to get Kinde authentication working correctly in this environment.
Cloudflare Workers have a different runtime environment than traditional Node.js servers. Some configurations that work on Vercel or standard Node.js deployments require adjustments for Cloudflare.
Before diving into setup, understand these critical differences when deploying Kinde auth to Cloudflare Workers:
| Consideration | Standard deployment | Cloudflare Workers |
|---|---|---|
| Environment variables | .env.local or platform UI | Public vars in wrangler.toml [vars]; secrets via wrangler secret put |
process.env access | Works by default | Requires nodejs_compat_populate_process_env flag |
| KindeProvider | Can be used in providers | Avoid for SSR - use server-side auth patterns |
Open your project in a terminal and install the OpenNext.js adapter for Cloudflare Workers with the following command:
npm install @opennextjs/cloudflare@latestInstall Wrangler CLI as a dev dependency:
npm i -D wrangler@latestCreate a new file called wrangler.toml in the root of your project and add the following content:
touch wrangler.toml"$schema" = "./node_modules/wrangler/config-schema.json"main = ".open-next/worker.js"name = "my-app"compatibility_date = "2026-02-06"compatibility_flags = [ "nodejs_compat", "nodejs_compat_populate_process_env"]
[assets]directory = ".open-next/assets"binding = "ASSETS"Update your package.json to include the following scripts:
"scripts": { ...your other scripts... "preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview", "deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy", "cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"}Preview your project in the Cloudflare environment using the following command:
npm run previewAdd the generated .open-next directory to your .gitignore file.
echo "/.open-next/" >> .gitignoreAuthorize Wrangler to access your Cloudflare account using the following command:
wrangler loginThis will open your default web browser, prompting you to log in to your Cloudflare account and authorize Wrangler. Once logged in, you’ll see a confirmation page.
Deploy your project to Cloudflare Workers using the following command:
npm run deployThis will deploy your project to Cloudflare Workers. You’ll get a link to see the changes.
Uploaded my-app (.. sec)Deployed my-app triggers (.. sec)https://<your-app-name>.<your-account-name>.workers.devVerify your deployment by visiting the health endpoint at the URL you got from the previous command:
https://<your-app-name>.<your-account-name>.workers.dev/api/auth/healthYou may see localhost:3000 as the redirect URLs in the response. This is expected because Cloudflare Workers doesn’t read variables from the .env.local file. We will update this in the next step.
If you are using a custom domain, configure the domain in Cloudflare first, then use your custom domain URL everywhere below — in KINDE_SITE_URL, KINDE_POST_LOGIN_REDIRECT_URL, KINDE_POST_LOGOUT_REDIRECT_URL in wrangler.toml, and in the Allowed callback URLs / Allowed logout redirect URLs in your Kinde dashboard.
In your Kinde dashboard, go to your application > Details and add the following URLs:
https://your-app-url.com/api/auth/kinde_callbackhttps://your-app-url.comSelect Save
Update your wrangler.toml to include the following variables. You can get these from your Kinde application’s Quick start page.
# ...your existing config...[vars]KINDE_CLIENT_ID = "your_client_id"KINDE_ISSUER_URL = "https://your_business.kinde.com"KINDE_SITE_URL = "https://your-app-url.com"KINDE_POST_LOGIN_REDIRECT_URL = "https://your-app-url.com/dashboard"KINDE_POST_LOGOUT_REDIRECT_URL = "https://your-app-url.com"When copying values from your .env.local file, make sure not to include the KINDE_CLIENT_SECRET value because the wrangler.toml file is only for storing public variables.
Set your client secret to Cloudflare using the following command:
npx wrangler secret put KINDE_CLIENT_SECRETRedeploy your project to Cloudflare Workers using the following command:
npm run deployVerify your deployment by visiting your app in the browser. Sign in or sign up with Kinde and you should be redirected to the dashboard page.
After deploying, you can verify your Kinde configuration by visiting:
https://your-app-url.com/api/auth/healthThis endpoint will show your SDK configuration (with secrets redacted) to help debug any issues. You should see your Kinde application’s details.
Cause:
The server returns 200 OK but the HTML body is empty. This is usually caused by KindeProvider being used in a way that breaks SSR on Cloudflare Workers.
Fix:
Remove KindeProvider from your providers and rely on server-side authentication patterns instead. Use the server-side authentication methods provided by the Kinde Next.js SDK.
Cause:
Clicking login redirects to localhost:3000 instead of your Kinde domain. Environment variables are not being read correctly, so the SDK falls back to development defaults when it can’t find the configuration.
Fix:
nodejs_compat_populate_process_env is in your compatibility_flags in wrangler.toml[vars] section of wrangler.toml (except KINDE_CLIENT_SECRET, which should be set via wrangler secret put)Cause:
After authenticating with Kinde, you’re redirected back with a “state not found” error. The authentication state cookie isn’t being persisted correctly between the redirect.
Fix:
KINDE_SITE_URL exactly matches the URL you’re accessing the app fromCause:
Auth works locally but fails in production with undefined configuration errors. Cloudflare Dashboard environment variables aren’t automatically available via process.env.
Fix:
Environment variables must be defined in wrangler.toml for the SDK to access them. The Cloudflare Dashboard variables are available as Worker bindings but not through process.env without the nodejs_compat_populate_process_env compatibility flag.
For more troubleshooting and information, see the Cloudflare Next.js documentation.