Overview

When deploying an application using Next Auth (Auth.js v5) to a Docker container or production environment, the following error occurs with GitHub OAuth authentication if the AUTH_URL environment variable is not configured:

BTehecarreedfiurle!ct_uriisnotassociatedwiththisapplication.

Development Environment vs Production Environment

Development Environment (npm run dev)

In the development environment, Next.js automatically detects host information, so configuring AUTH_URL is not required.

#npTmhirsunaldoenveworks

Production Environment (Docker / npm run build && npm start)

In the production environment, Next Auth cannot automatically detect host information, so configuring AUTH_URL is required.

#AAUUATTdHHd__UTtRRoLU=S.hTet_ntHvpO.:SlT/=cltaorlcuaeolrhoesntv:i3r0o0n0men#tovrarhitatbplse:s//your-domain.com

Docker Configuration Examples

Using docker run

doc-mk-eyeearnApvUpr-T:ufHlni_alTt-eRedUs.SteT-n_nvHa.OmlSeoTc=matylraup\ep\-p3000:3000\

Using docker-compose.yml

seravpipipeec:monnear-v--vsgti_:es"rAAf.::3oUUie0nTTlnm0mHHevy0e__:.a:nUTlp3tRRop0:LUc:0=Sal0hTla"t_ttHepOssSt:T/=/tyrouuer-domain.com

List of Required Environment Variables

Variable NameDevelopment EnvironmentProduction EnvironmentDescription
AUTH_SECRETRequiredRequiredSession encryption key
AUTH_GITHUB_IDRequiredRequiredGitHub OAuth Client ID
AUTH_GITHUB_SECRETRequiredRequiredGitHub OAuth Client Secret
AUTH_URLNot requiredRequiredApplication base URL
AUTH_TRUST_HOSTNot requiredRequiredConfiguration to trust the host

.env.local Example

#A#AA#AUUUUNTGTTPTeHiHHrHx_t__o_tSHGGdUAEuIIuRuCbTTcLtRHHt=hEOUUih.TABBotj=u__ntsytISpohDEo:Cu=Cn/orAyRl/n-poEylfspuToier=(cgcC-yDaurrcoolreeluchatdirkot-ee-esiknncrtoettl:nyi-i/3-aie0hldnd0este0r-pesleocyreedtenvironments)

Why This Problem Occurs

  1. Development environment: The Next.js development server can obtain accurate host information from request headers
  2. Production environment: Inside a Docker container, it starts as 0.0.0.0:3000, so it does not know the actual URL when accessed from outside
  3. OAuth mechanism: GitHub only allows redirects to URLs that exactly match the registered redirect_uri

Troubleshooting

Error: “redirect_uri is not associated with this application”

Cause: AUTH_URL is not configured, or it does not match the GitHub OAuth App’s Callback URL

Solution:

  1. Configure AUTH_URL correctly
  2. Set {AUTH_URL}/api/auth/callback/github as the “Authorization callback URL” in the GitHub OAuth App

Error: “UntrustedHost: Host must be trusted”

Cause: AUTH_TRUST_HOST is not configured

Solution: Add AUTH_TRUST_HOST=true to the environment variables


Created: 2026-01-27