Skip to content

abhi24112/Next.js-Authentication-Project

Repository files navigation

Next.js Authentication Project

This is a modern Next.js project demonstrating a complete user authentication flow including MongoDB database, signup, login, profile management, password reset, and email verification.


Table of Contents


Getting Started

To add for the package from package.json

npm i

To run the development server:

npm run dev

Open http://localhost:3000 in your browser to view the app.


Features

  • User Signup with email verification
  • User Login and session management
  • Profile page with user details
  • Forgot password and reset password functionality
  • Email notifications for verification and password reset using Mailtrap
  • Secure token-based password reset links

Project Structure

  • src/app/ - Contains all the Next.js app routes and pages
  • src/app/api/users/ - API routes for user authentication and management
  • src/models/ - User model and database schema using MongoDB and Mongoose
  • src/helpers/ - Helper functions including mailer integration
  • src/middleware.ts - Middleware for route protection and validation

Database

This project uses MongoDB as the database and Mongoose as the ODM (Object Data Modeling) library to define schemas and interact with MongoDB.

You can view and manage your MongoDB data using tools like MongoDB Compass.

Example MongoDB Data View

MongoDB Data


Pages Overview

  • Sign In - User registration page
  • Login - User login page
  • Profile - User profile management page
  • Forgot Password - Request password reset link
  • Reset Password - Set a new password using a secure token
  • Email Verification - Verify user email after signup

Email Integration

This project uses Mailtrap for capturing and testing emails during development. Due to domain and DNS permission constraints required for sending real emails, this project uses Mailtrap's sandbox environment for email testing.

It handles:

  • Verification emails after signup
  • Password reset emails with secure token links

Usage

  1. Signup a new user on the Sign In page.
  2. Check Mailtrap inbox for verification email and verify your account.
  3. Login with verified credentials.
  4. Access your profile page.
  5. Use Forgot Password page to request a password reset link.
  6. Use the Reset Password page accessed via the emailed token link to set a new password.

Screenshots

Sign In Page

Sign In

Login Page

Login

Profile Page

Profile

Forgot Password Page

Forgot Password

Reset Password Page

Reset Password

Mailtrap Email Example

Reset Password Mail

Mailtrap Email

Verify User Mail

Mailtrap Email


Learn More


Deployment

The easiest way to deploy this Next.js app is using Vercel. See Next.js deployment docs for details.


Feel free to contribute or raise issues on the GitHub repository.

About

Next.js Authentication Project: A modern, full-featured user authentication system built with Next.js, MongoDB, and Mongoose. Features include user signup with email verification, login, profile management, password reset with secure token links, and email notifications using Mailtrap sandbox for development testing.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages