I have same problem, but just putting the container name on the variable seems to not work. I tried several ways. It only occurs on docker, they are on the same network
2025-03-31 18:59:11 Error during authorization: TypeError: fetch failed
2025-03-31 18:59:11 at node:internal/deps/undici/undici:12637:11
2025-03-31 18:59:11 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2025-03-31 18:59:11 at async Object.authorize (/app/.next/server/app/api/auth/[...nextauth]/route.js:1:1705)
2025-03-31 18:59:11 at async Object.c (/app/.next/server/app/api/auth/[...nextauth]/route.js:30:4474)
2025-03-31 18:59:11 at async _ (/app/.next/server/app/api/auth/[...nextauth]/route.js:6:104099)
2025-03-31 18:59:11 at async a (/app/.next/server/app/api/auth/[...nextauth]/route.js:30:19579)
2025-03-31 18:59:11 at async e.length.t (/app/.next/server/app/api/auth/[...nextauth]/route.js:30:20990)
2025-03-31 18:59:11 at async /app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:34666
2025-03-31 18:59:11 at async eS.execute (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:25813)
2025-03-31 18:59:11 at async eS.handle (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:35920) {
2025-03-31 18:59:11 cause: Error: connect ECONNREFUSED ::1:8080
2025-03-31 18:59:11 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
2025-03-31 18:59:11 at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:128:17) {
2025-03-31 18:59:11 errno: -111,
2025-03-31 18:59:11 code: 'ECONNREFUSED',
2025-03-31 18:59:11 syscall: 'connect',
2025-03-31 18:59:11 address: '::1',
2025-03-31 18:59:11 port: 8080
2025-03-31 18:59:11 }
2025-03-31 18:59:11 }
i am entering the env variable in docker like this:
environment:
- NEXTAUTH_URL=http://localhost:3000/
- NEXT_PUBLIC_API_URL=http://test:8080
My docker compose:
services:
db:
image: postgres:16.4
container_name: postgres
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
networks:
- test-network
test:
image: test/test:1.0.0
environment:
- TEST_FRONT_URL=http://localhost:3000
ports:
- "8080:8080"
depends_on:
- db
networks:
- test-network
test-next:
image: test/test-next:1.0.0
ports:
- "3000:3000"
environment:
- NEXTAUTH_URL=http://localhost:3000/
- NEXT_PUBLIC_API_URL=http://test:8080
networks:
- test-network
volumes:
pgdata:
networks:
test-network:
name: test-network
driver: bridge