nextauthjs / nextauthjs/next-auth

trustHost = false causes odd session object containing only a message property

Open
#13,342 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

Environment
 % pnpm dlx envinfo --system --binaries --browsers --npmPackages "{next,react,next-auth,@auth/*}"
Packages: +1
+
Progress: resolved 1, reused 0, downloaded 1, added 1, done

  System:
    OS: macOS 15.6.1
    CPU: (10) arm64 Apple M4
    Memory: 73.69 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.1 - /Users/stevenlybeck/.nvm/versions/node/v22.15.1/bin/node
    npm: 10.9.2 - /Users/stevenlybeck/.nvm/versions/node/v22.15.1/bin/npm
    pnpm: 10.24.0 - /Users/stevenlybeck/Library/pnpm/pnpm
  Browsers:
    Chrome: 143.0.7499.41
    Firefox: 145.0.2
    Safari: 18.6
  npmPackages:
    next: ^16.0.9 => 16.0.9 
    next-auth: 5.0.0-beta.30 => 5.0.0-beta.30 
    react: ^19.2.2 => 19.2.2 
Reproduction URL

https://github.com/stevenlybeck/psychic-octo-giggle/tree/main

Describe the issue

I had a problem where when I moved to NODE_ENV=production I started getting "Host must be trusted." error logs - and more significantly, my app was skipping any login flow and attempting to render the logged-in version.

The page code is below - and in spite of the "Host must be trusted." config error, the session object returned as truthy and my app tried to render.

export default async function Home() {
  const session = await auth()

  if (!session) {
    redirect('/login')
  }

  return <App />
}

I eventually tracked this down and I'm resolving it by just using the AUTH_URL env var which will implicitly set trustHost

But it seems off for auth() to return an object like {message: "There was a problem with the server configuration. Check the server logs for more information."} - it doesn't conform to Session interface the auth() function is intended to return, and breaks null checks on the returned session object.

How to reproduce
export default async function Home() {
  const session = await auth()

  if (!session) {
    redirect('/login')
  }

  return <App />
}
  • Notice that as result of the UntrustedHost error, auth() returns an object with an unexpected 'message' property.

Code debugging:

At the very least this seems to break type checking because the auth function is supposed to return an object conforming to the Session interface

Expected behavior

auth() function returns a value compliant with the type definitions in NextAuthResult.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/core/src/index.ts, especially the assertConfig handling, then follow the response through packages/next-auth/src/lib/index.ts and the NextAuthResult and Session definitions in packages/next-auth/src/index.ts and packages/core/src/types.ts. Confirm how an UntrustedHost response reaches auth(); done means the returned value conforms to the documented session result instead of exposing only a message property.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, react, typescript
Domain
authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.