Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Learn how to secure subdomains using Next.js and NextAuth.

Free HTML tutorials and code components built with Tailwind CSS and Alpine.js from Cruip.

Open-source handbook and Nuxt documentation site for engineering effectiveness, with Markdown content and static generation.

BC Web Mapping Technological Solutions And Experiences
Auth for subdomains is a Vercel example project that demonstrates how to secure subdomains in a Next.js application using NextAuth.js for authentication.
Auth for subdomains is a working reference implementation that pairs Next.js with NextAuth.js to authenticate users across a main domain and its subdomains. It takes GitHub OAuth credentials and a secret as environment variables, runs as a Next.js app, and produces a login flow where authentication state is shared between the main domain and a subdomain. The example is maintained by Vercel as part of its public examples repository on GitHub.
pnpm create next-app pointing at the GitHub example, then run pnpm dev for development.The example is bootstrapped with pnpm create next-app from the Vercel examples repository. After installing dependencies, you run pnpm dev, then set the GITHUB_ID, GITHUB_SECRET, and SECRET environment variables. Visiting the root domain triggers the GitHub OAuth login, and the resulting session is valid on the connected subdomain.
The deploy configuration requires GITHUB_ID, GITHUB_SECRET, and SECRET. GITHUB_ID and GITHUB_SECRET come from a GitHub OAuth app you create, while SECRET is used by NextAuth.js to encrypt session data.
Log in from the main demo URL (solutions-subdomain-auth.vercel.sh), then visit the subdomain (subdomain.solutions-subdomain-auth.vercel.sh). The exercise is designed so that you log in from the root domain and are recognized on the subdomain.
The example's project metadata lists Tailwind as the CSS approach, though the documentation page focuses on the authentication logic rather than styling details.
