Next.js Authentication Across Multiple Subdomains: A Complete Guide

Most products outgrow a single hostname. A marketing site lives at www.example.com, the product at app.example.com, an admin console at admin.example.com, and an API at api.example.com. Users expect to sign in once and move between them without seeing another login screen.

On paper, the fix looks like one cookie attribute. In practice, Next.js authentication across multiple subdomains touches cookie scoping, CORS, CSRF, local development, deployment and the security of every hostname under your domain. A setup that works on your laptop can fail silently in production, or work in a way that quietly widens your attack surface.

This guide covers how browsers scope cookies, three architectures you can choose from, a working shared-session implementation with the Next.js App Router, an Auth.js configuration, credentialed API calls between subdomains, local and Vercel setup, multi-tenant considerations, and a security checklist.

Contents