{"repo":"heterl0/nextjs-multi-tenant-with-auth","free":true,"listed":false,"github":"https://github.com/heterl0/nextjs-multi-tenant-with-auth","clone":"git clone https://github.com/heterl0/nextjs-multi-tenant-with-auth.git","description":"NextJs Multi-Tenant with Auth","language":"TypeScript","stars":11,"topics":["authentication","multitanent","nextjs"],"license":null,"category":"auth-billing-email","readme_excerpt":"Multi-Tenant Applications with Next.js: Subdomain with Auth Introduction Multi-tenancy is a software architecture where a single instance of an application serves multiple tenants (customers or users). This README outlines how to create a multi-tenant application using Next.js with subdomain-based tenant separation. Key Features of Multi-Tenancy - Shared Infrastructure 📈 - Tenant Isolation 🔒 - Cost Efficiency 💸 - Scalability 🚀 Project Structure Middleware Implementation The middleware.ts file handles routing, authentication, and request rewriting based on subdomains: How It Works 1. Subdomain Detection 📍: Extract subdomain from the host header. 2. Authentication 🔑: Redirect unauthenticated users to the login subdomain. 3. Route Rewriting 🔄: Rewrite requests to serve tenant-specific pages. 4. Cookie Management 🍪: Set userId cookie upon successful authentication. Implementation Steps 1. Domain Configuration 📊: Point main domain and subdomains to the same server. 2. Environment Variables 📝: Define root domain in .env file. 3. Local Development 💻: Use host aliases or local DNS tools for testing. 4. Authentication Flow 🔒: Create login page at login.yourdomain.com . 5. Tenant-Specific Pages 📁: Build pages in the [subdomain] directory. Advantages - Scalability 🚀 - Isolation 🔒 - Flexibility 🎨 Demo Check out the live demo to see the multi-tenant application in action. Multi-tenant Demo 📹 Disclaimer This approach is based on personal experience and may not be the most ","default_branch":null,"files":null,"tree":[],"storefront":"/r/heterl0","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/heterl0/nextjs-multi-tenant-with-auth/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}