An open API service indexing awesome lists of open source software.

https://github.com/lskeey/next-auth-v5

Authentication solution for Next.js apps, providing seamless and secure user login with NextAuth.js v5.
https://github.com/lskeey/next-auth-v5

authjs nextjs postgresql shadcn-ui tailwindcss

Last synced: 3 months ago
JSON representation

Authentication solution for Next.js apps, providing seamless and secure user login with NextAuth.js v5.

Awesome Lists containing this project

README

          


🛡️ NEXT-AUTH-V5


Seamless Security, Limitless Possibilities


Last Commit
TypeScript Percentage
Languages Count


Login Page

Built with the tools and technologies:


JSON
Markdown
Resend
NPM
PostCSS
JavaScript
React
TypeScript
Prisma
Zod
ESLint
React Hook Form


This project is a robust, full-featured authentication system built with Next.js App Router and Next-Auth v5. It provides a modern, secure, and highly customizable foundation for your web applications, handling everything from user registration to multi-factor authentication.

## ✨ Key Features

- **Credentials & Social Authentication**: Secure login via email and password, or seamlessly with Google and GitHub OAuth providers.
- **Email Verification**: A streamlined process to confirm new user accounts through email, enhancing security and preventing spam.
- **Password Reset**: Built-in functionality for users to securely reset their forgotten passwords.
- **Two-Factor Authentication (2FA)**: An extra layer of security with two-factor authentication, using an OTP sent to the user's email.
- **Role-Based Access Control**: Protect your routes and server actions based on user roles (Admin/User), ensuring proper authorization throughout your application.
- **Client & Server Component Protection**: Middleware protects routes from unauthorized access, both on the client and server sides.
- **Modern UI**: Beautiful and responsive design, crafted using **Shadcn/UI** and **Tailwind CSS**.

## 🚀 Getting Started

Follow these simple steps to get the project up and running on your local machine.

### Prerequisites

- Node.js (>= 18.17.0)
- PostgreSQL or another supported database for Prisma
- A **Resend** API key for sending emails.
- **Google** and **GitHub** OAuth client IDs and secrets for social logins.

### Installation

1. **Clone the repository**:
```bash
git clone https://github.com/lskeey/next-auth-v5.git
cd next-auth-v5
```

2. **Install dependencies**:
```bash
npm install
# or
yarn install
# or
pnpm install
```

3. **Set up environment variables**:
Create a `.env` file at the root of the project and copy the contents from `.env.example`. Replace the placeholder values with your own keys.
```env
# Prisma connection string
DATABASE_URL=

# Next-Auth secret
AUTH_SECRET=

# OAuth providers
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# Resend API key for emails
RESEND_API_KEY=
```

4. **Database Setup**:
Initialize and migrate your database using Prisma.
```bash
npx prisma migrate dev
```

5. **Run the development server**:
```bash
npm run dev
```
Open [http://localhost:3000](http://localhost:3000) in your browser.

## 📂 Project Structure

- `actions/`: Server actions for handling authentication logic (e.g., login, register, reset).
- `app/`: Next.js App Router for all pages and API routes.
- `components/`: Reusable UI components including form wrappers, buttons, and user information displays.
- `data/`: Data access layer for interacting with the database using Prisma.
- `hooks/`: Custom React hooks for client-side state management, like fetching the current user or role.
- `lib/`: Core utility functions, including database connection, authentication helpers, and mailer setup.
- `prisma/`: Prisma schema and database configuration.
- `schemas/`: Zod schemas for form validation.

## 🤝 Contribution

Contributions are welcome! If you'd like to improve this project, please feel free to open an issue or submit a pull request.

## 📄 License

This project is licensed under the MIT License.