KindeK
Kinde2y ago
13 replies
jessebs

next.config.js Kinde Env Vars

I'm trying to set some of my KINDE environment variables in my next.config.js file in order to support preview deployments. Here's a minimal example:

...
  env: {
    KINDE_SITE_URL: "http://localhost:3000",
    KINDE_POST_LOGOUT_REDIRECT_URL: "http://localhost:3000",
    KINDE_POST_LOGIN_REDIRECT_URL: "http://localhost:3000/dashboard"
  }
}

module.exports = nextConfig


I do not have any of the 3 env variables set elsewhere

When I visit my application, I get the following error:
⨯ TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:405:5)
    at new URL (node:internal/url:676:13)
    at new t (/Users/me/projects/my-project/node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/cjs/index.js:1:29570)
    at /Users/me/projects/my-project/node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/cjs/index.js:1:30927
    at f (/Users/me/projects/my-project/node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/cjs/index.js:1:1537)
    at Generator.<anonymous> (/Users/me/projects/my-project/node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/cjs/index.js:1:2887)
... {
  input: 'undefined/api/auth/login',
  code: 'ERR_INVALID_URL',
  page: '/api/auth/[...kindeAuth]'


This works if I set the variables through a .env file but my understanding from https://kinde.com/docs/developer-tools/nextjs-sdk/#working-with-preview-urls is that it should work without previously having set the values.
Kinde Docs
Our developer tools provide everything you need to get started with Kinde.
NextJS App Router SDK v2 - Developer tools - Help center
Was this page helpful?