https://github.com/alexchantastic/next-password-protect-example
An example Next.js project with password protected routes
https://github.com/alexchantastic/next-password-protect-example
app-router auth next nextjs password password-protect react-server-components rsc
Last synced: 5 months ago
JSON representation
An example Next.js project with password protected routes
- Host: GitHub
- URL: https://github.com/alexchantastic/next-password-protect-example
- Owner: alexchantastic
- Created: 2024-02-08T23:29:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-07T08:11:58.000Z (11 months ago)
- Last Synced: 2024-11-07T09:21:42.673Z (11 months ago)
- Topics: app-router, auth, next, nextjs, password, password-protect, react-server-components, rsc
- Language: TypeScript
- Homepage: https://codesandbox.io/p/devbox/github/alexchantastic/next-password-protect-example/tree/main/
- Size: 120 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# next-password-protect-example
This is an example project that demonstrates how to password protect routes with [Next.js](https://nextjs.org/) (App Router) and [iron-session](https://github.com/vvo/iron-session).
Read the full walkthrough at [https://www.alexchantastic.com/revisiting-password-protecting-next](https://www.alexchantastic.com/revisiting-password-protecting-next).
## Setup
Clone the repository:
```sh
git clone git@github.com:alexchantastic/next-password-protect-example.git
```Change directories into the project and install dependencies:
```sh
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"
```## Usage
Run the development server:
```sh
npm run dev
```Open [http://localhost:3000](http://localhost:3000) with your browser.
## Project structure
```
src/
└── app/
├── api/
├── middleware-protected/
│ └── nested-middleware-protected/
├── protected/
├── sign-in/
└── unprotected/
```