Auth.js · server log

UntrustedHost

what it looks like
[auth][error] UntrustedHost: Host must be trusted. URL was: https://your-app.com/api/auth/session. Read more at https://errors.authjs.dev#untrustedhost

What it means

Auth.js builds callback URLs from the request's Host header and refuses to trust it by default in production. In development (NODE_ENV not production) it trusts the host automatically, which is why this only appears after you deploy.

Common causes

  • Running next start, Docker, Railway, Fly, Render or a VPS behind a proxy
  • Vercel and Cloudflare Pages are detected automatically (VERCEL / CF_PAGES env vars), most other hosts are not

How to fix it

  1. Set trustHost: true in your NextAuth config, or
  2. Set AUTH_TRUST_HOST=true in the production environment
  3. Setting AUTH_URL also counts as trusting the host
src/auth.ts
export const { handlers, auth, signIn, signOut } = NextAuth({
  trustHost: true, // needed for next start, Docker and most non-Vercel hosts
  providers: [GitHub],
});

works with next-auth 5.0.0-beta.32 · @auth/core 0.41.3 · Next.js 16.4.3last verified

Prompt for Cursor or Claude Code

Auth.js logs UntrustedHost after deploying with next start. Add trustHost: true to the NextAuth config in auth.ts (or tell me to set AUTH_TRUST_HOST=true on the host) and explain why it worked locally.

Not quite your error? Paste yours into the free VibeBoot Doctor or browse the Auth.js error fixer.

next: skip the next one

Skip the debugging. The VibeBoot SaaS Starter ships with this already handled: src/auth.ts sets trustHost and ships GitHub sign-in, and .env.example documents AUTH_SECRET and the GitHub callback URL. Plus Stripe and a database on Next.js 16.4.3. $49, one-time.

14-day money-back guarantee · lifetime updates

$ fixed it? get the next one first

New fixes for what AI agents break, by email.

When we add a fix or a Cursor rule for a new Next.js, Auth.js, Prisma or Stripe break, it goes out in the VibeBoot newsletter. Free, occasional, unsubscribe in one click.

Subscribe free