https://github.com/boolfalse/nextjs-auth
Next.js authentication boilerplate
https://github.com/boolfalse/nextjs-auth
Last synced: 11 months ago
JSON representation
Next.js authentication boilerplate
- Host: GitHub
- URL: https://github.com/boolfalse/nextjs-auth
- Owner: boolfalse
- Created: 2024-02-11T23:16:25.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-16T22:23:41.000Z (almost 2 years ago)
- Last Synced: 2025-01-10T06:58:52.781Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 103 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Next.js Authentication Boilerplate
### Installation
- Install dependencies:
```bash
npm i
```
- Create a MongoDB cluster and get the connection string from the [MongoDB dashboard](https://cloud.mongodb.com/).
- Create a `.env` file in the root directory as per the `.env.example` file:
```shell
cp .env.example .env
```
- Set MongoDB credentials in the `.env` file:
```dotenv
MONGODB_USER="user"
MONGODB_PASSWORD="password"
MONGODB_DATABASE="database"
MONGODB_CLUSTER="cluster0"
MONGODB_DOMAIN="mzcsh.mongodb.net"
```
- Generate a secret key:
```shell
openssl rand -base64 32
```
- Set `AUTH_SECRET` and `NEXTAUTH_URL` in the `.env` file:
```dotenv
NEXTAUTH_SECRET=""
NEXTAUTH_URL="http://localhost:3000"
```
- Set the `ADMIN_EMAIL` in the `.env` file (GitHub email used in this example):
```dotenv
ADMIN_EMAIL="admin@gmail.com"
```
- Create a [GitHub OAuth app](https://github.com/settings/developers) and set the `GITHUB_ID` and `GITHUB_SECRET` in the `.env` file:
```dotenv
GITHUB_ID=""
GITHUB_SECRET=""
```
- Run the server:
```bash
npm run dev
# or
npm start
```
- Open [http://localhost:3000](http://localhost:3000) on your browser.
### Resources
- [Next.js Authentication - AuthJS / NextAuth for Role-Based Security](https://www.youtube.com/watch?v=MNm1XhDjX1s)
- [ClarityCoders/NextAuthTutorial-Video](https://github.com/ClarityCoders/NextAuthTutorial-Video)
- [Next.js 14 Admin Dashboard Tutorial | Fullstack Next.js 14 Project with Server Actions](https://www.youtube.com/watch?v=cBg6xA5C60s)
- [safak/nextadmin](https://github.com/safak/nextadmin/tree/completed)
- [Credentials authentication](https://authjs.dev/getting-started/providers/credentials-tutorial)
- [Protecting your routes with Next.js Middleware](https://nextjs.org/learn/dashboard-app/adding-authentication#protecting-your-routes-with-nextjs-middleware)
- [Authentication](https://nextjs.org/docs/pages/building-your-application/authentication)
- [Error: NEXT_REDIRECT while using server actions #49298](https://github.com/vercel/next.js/issues/49298#issuecomment-1542055642)
- [User object is empty #2762](https://github.com/nextauthjs/next-auth/discussions/2762)
### Author
- [BoolFalse](https://boolfalse.com/)