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 git@github.com:alexchantastic/next-password-protect-example.gitChange directories into the project and install dependencies:
cd next-password-protect-example
npm installCreate 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 devOpen http://localhost:3000 with your browser.
src/
└── app/
├── api/
├── middleware-protected/
│ └── nested-middleware-protected/
├── protected/
├── sign-in/
└── unprotected/