---
title: "Auth for subdomains"
description: "Learn how to secure sub domains using Next.js and NextAuth."
url: "https://vercel.com/templates/next.js/subdomains-auth"
links:
  repository: "https://github.com/vercel/examples/tree/main/solutions/subdomain-auth"
  demo: "https://solutions-subdomain-auth.vercel.sh"
  deploy: "https://vercel.com/new/clone?demo-title=Auth+for+subdomains&demo-description=Learn+how+to+secure+sub+domains+using+Next.js+and+NextAuth.&demo-url=https%3A%2F%2Fsolutions-subdomain-auth.vercel.sh&demo-image=%2F%2Fimages.ctfassets.net%2Fe5382hct74si%2F1GTDO1rk67nzyPmBLNPqCN%2F6932e92fd95a7ed017ec15167a3e2637%2Fsolutions-subdomain-auth.vercel.sh_.png&project-name=Auth+for+subdomains&repository-name=subdomains-auth&repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fexamples%2Ftree%2Fmain%2Fsolutions%2Fsubdomain-auth&from=templates&skippable-integrations=1&env=GITHUB_ID%2CGITHUB_SECRET%2CSECRET"
---

# Auth for subdomains

Learn how to secure sub domains using Next.js and NextAuth.

- [solutions-subdomain-auth.vercel.sh](https://solutions-subdomain-auth.vercel.sh) (login from here)
- [subdomain.solutions-subdomain-auth.vercel.sh](https://subdomain.solutions-subdomain-auth.vercel.sh)

### Features

- Secure sub domains

### How to Use

You can choose from one of the following two methods to use this repository:

**Clone and Deploy**

Download this repository via git:

```bash
git clone https://github.com/vercel/examples.git
```

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example https://github.com/vercel/examples/tree/main/solutions/subdomain-auth subdomain-auth
# or
yarn create next-app --example https://github.com/vercel/examples/tree/main/solutions/subdomain-auth subdomain-auth
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=edge-middleware-eap) ([Documentation](https://nextjs.org/docs/deployment)).

## Related Templates

### [Basic Auth Password Protection](https://vercel.com/templates/next.js/basic-auth-password)

Password protect pages in your application using Edge Middleware.

---

## Additional documentation

The [Vercel Knowledge Base](https://vercel.com/kb) contains guides and answers to common questions about Vercel, including deployment, framework configuration, domains, caching, and troubleshooting.
