This is an example project that demonstrates how to password protect routes with Next.js (App Router) and iron-session.
Read the full walkthrough at https://www.alexchantastic.com/revisiting-password-protecting-next.
Clone the repository:
git clone [email protected]:alexchantastic/next-password-protect-example.git
Change directories into the project and install dependencies:
cd next-password-protect-example
npm install
Create an .env.local
file:
IRON_SESSION_SECRET="replace_with_your_secret" # Must be at least 32 characters
IRON_SESSION_PASSWORD="replace_with_your_password"
Run the development server:
npm run dev
Open http://localhost:3000 with your browser.
src/
└── app/
├── api/
├── middleware-protected/
│ └── nested-middleware-protected/
├── protected/
├── sign-in/
└── unprotected/