Skip to content

UNABLE_TO_GET_ISSUER_CERT_LOCALLY when testing locally with SSL #3580

@zomars

Description

@zomars

Description 🐜

I have a local setup that allows me to use domains with HTTPS by default ex (https://example.localhost) using Caddy and dnsmasq.

A normal NextJS project works just fine. But when using a project with next-auth we get this error:

[next-auth][error][client_fetch_error]
https://next-auth.js.org/errors#client_fetch_error csrf FetchError: request to https://example.localhost/api/auth/csrf failed, reason: unable to get local issuer certificate
    at ClientRequest.<anonymous> (/Users/zomars/Sites/example/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (events.js:400:28)
    at ClientRequest.emit (domain.js:470:12)
    at TLSSocket.socketErrorListener (_http_client.js:475:9)
    at TLSSocket.emit (events.js:400:28)
    at TLSSocket.emit (domain.js:470:12)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  type: 'system',
  errno: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
  code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'
}
10:50:25.140 timeZoneName DEBUG [error] server side logged this: Error: Error serializing `.csrfToken` returned from `getServerSideProps` in "/auth/login".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.
10:50:25.141 timeZoneName INFO [error] return props,
{
  statusCode: 500,
  hasGetInitialPropsRun: true
}

Is this a bug in your own project?

No

How to reproduce ☕️

  • Run a secure server with caddy:
    caddy reverse-proxy --from example.localhost --to localhost:3000
  • Setup NEXTAUTH_URL
    NEXTAUTH_URL='https://example.localhost/api/auth'
  • Try to login and see the error in the logs.

Screenshots / Logs 📽

No response

Environment 🖥

System:
OS: macOS 11.6.2
CPU: (8) x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
Memory: 659.78 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
Browsers:
Brave Browser: 96.1.33.106
Chrome: 96.0.4664.110
Chrome Canary: 84.0.4136.1
Firefox: 72.0.2
Firefox Developer Edition: 96.0
Safari: 15.2
Safari Technology Preview: 15.4
npmPackages:
next: ^12.0.7 => 12.0.7
next-auth: ^3.29.0 => 3.29.0
react: ^17.0.2 => 17.0.2

Contributing 🙌🏽

Yes, I am willing to help solve this bug in a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions