Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

NextAuth shows 'There is a problem with the server configuration'

ErrorThere is a problem with the server configuration.

Short answer

That page is NextAuth's generic Configuration error: your auth setup is wrong on the server, not the browser. Check the server terminal first. The usual causes are a missing secret in production, a missing [...nextauth] route file, a Credentials provider without an authorize function, or an Email provider without a database adapter.

  • Applies to next-auth 4, Next.js 15, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the terminal or hosting log of the server that handles /api/auth. NextAuth prints its own error code there; match it to a cause below.

    npm run build && npm run start
  2. 2Match what you see, then jump to its fix

    1. 1NO_SECRET: in production, we expect you to define a secret property in your configurationNo secret is set in productionFix
    2. 2MISSING_NEXTAUTH_API_ROUTE_ERRORThe [...nextauth] route file is missing or misnamedFix
    3. 3CALLBACK_CREDENTIALS_HANDLER_ERROR or CALLBACK_CREDENTIALS_JWT_ERRORCredentials provider without authorize, or with database sessionsFix
    4. 4EMAIL_REQUIRES_ADAPTER_ERROREmail provider without a database adapterFix
    5. 5UntrustedHost: Auth.js requires the trustHost option to be set to trueAuth.js v5 behind a proxy or Docker does not trust the hostFix

What does the error look like?

  • There is a problem with the server configuration.
  • Check if your options are correct.
  • /api/auth/error?error=Configuration

Cause 1 of 5

No secret is set in production

1Check

The docs say a secret is expected in production (in development it is only a warning). See whether the production environment really has the variable your config reads.

grep -rn "secret" app pages lib auth.ts 2>/dev/null
printenv NEXTAUTH_SECRET | wc -c

2Fix

Generate a random value, add it to the production environment and redeploy, so the server process restarts with it.

openssl rand -base64 33
# then set NEXTAUTH_SECRET=<that value> in the host's environment settings

3Verify

Open the sign-in page after the redeploy; the Configuration page should be gone.

curl -I https://example.com/api/auth/signin

Confirmed by next-auth.js.org

Did this fix it?

Cause 2 of 5

The [...nextauth] route file is missing or misnamed

1Check

The docs name this case: the dynamic route file must exist under pages/api/auth and be spelled exactly [...nextauth].js.

find . -path ./node_modules -prune -o -name "*nextauth*" -print

2Fix

Create or rename the file so the catch-all segment is [...nextauth], and export the NextAuth handler from it.

// pages/api/auth/[...nextauth].js
import NextAuth from "next-auth"
export default NextAuth({ providers: [] /* your providers */ })

3Verify

Restart the dev server and request the providers endpoint; it should return JSON.

curl http://localhost:3000/api/auth/providers

Confirmed by next-auth.js.org

Did this fix it?

Cause 3 of 5

Credentials provider without authorize, or with database sessions

1Check

The docs say the Credentials provider needs an authorize() handler, and it needs JWT sessions. If you also configured a database adapter, enable JWT sessions explicitly.

grep -n -E "CredentialsProvider|authorize|strategy" pages/api/auth/*.js app/api/auth/*/route.ts 2>/dev/null

2Fix

Add authorize() to the provider and set the session strategy to jwt.

session: { strategy: "jwt" },
providers: [
  CredentialsProvider({
    credentials: { email: {}, password: {} },
    async authorize(credentials) {
      // return a user object, or null to reject
      return null
    },
  }),
],

3Verify

Sign in once with a wrong password. You should get the normal sign-in error, not the Configuration page.

curl -s http://localhost:3000/api/auth/providers

Confirmed by next-auth.js.org

Did this fix it?

Cause 4 of 5

Email provider without a database adapter

1Check

The docs say the Email provider needs a configured database to store verification tokens.

grep -n -E "EmailProvider|adapter" pages/api/auth/*.js app/api/auth/*/route.ts 2>/dev/null

2Fix

Add a database adapter to the NextAuth options, or remove the Email provider if you do not need magic links.

// in the NextAuth options, next to providers:
adapter: yourDatabaseAdapter,

3Verify

Restart the server and request the providers endpoint; the Configuration page should no longer appear.

curl -s http://localhost:3000/api/auth/providers

Confirmed by next-auth.js.org

Did this fix it?

Cause 5 of 5

Auth.js v5 behind a proxy or Docker does not trust the host

1Check

Auth.js v5 reads the host from request headers, so it must be told to trust them. The docs say this is automatic on some platforms only (Vercel and Cloudflare Pages are named).

printenv | grep -E "AUTH_TRUST_HOST|AUTH_SECRET"

2Fix

Set trustHost: true in the config, or the AUTH_TRUST_HOST environment variable to true.

AUTH_TRUST_HOST=true

3Verify

Restart the container and request the sign-in page through the proxy.

curl -I https://example.com/api/auth/signin

Confirmed by authjs.dev

Did this fix it?

How do I stop it coming back?

  • Keep the auth secret in the host's environment settings and add a deploy check that fails when it is empty.
  • Test sign-in against a production build (next build and next start) before every release, not only the dev server.
  • Read the server log, not the browser, when an auth page shows a generic message.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.