Skip to content

Repository files navigation

🔐 Authentication System

A Secure Full-Stack Authentication System built with Next.js 16

A production-inspired authentication system implementing secure user registration, login, email verification, password recovery, JWT authentication and protected routes using modern web technologies.


Next.jsTypeScriptMongoDBJWT


📖 Overview

Authentication is the backbone of almost every modern web application.

This project demonstrates how a complete authentication workflow can be implemented using the latest Next.js App Router, MongoDB, and TypeScript while following secure authentication practices.

Instead of stopping at basic login/signup, this application implements the entire authentication lifecycle including email verification, password recovery, protected routes and secure JWT cookie-based sessions.


✨ Features

🔑 Authentication

  • User Registration
  • Secure Login
  • Secure Logout
  • JWT Authentication
  • HTTP-only Authentication Cookies
  • Protected Routes
  • User Session Handling

📧 Email Features

  • Email Verification
  • Verification Token Generation
  • Forgot Password Workflow
  • Password Reset via Email
  • Secure Reset Tokens
  • Token Expiration Support

🔒 Security

  • Password Hashing using bcrypt
  • JWT Token Authentication
  • HTTP-only Cookies
  • Protected API Routes
  • Authentication Middleware
  • Environment Variable Configuration
  • Secure Password Storage

💻 Backend

  • Next.js 16 App Router
  • API Route Handlers
  • MongoDB Database
  • Mongoose ODM
  • Nodemailer Integration
  • TypeScript
  • Modular Project Structure

🎨 Frontend

  • Responsive UI
  • Modern Forms
  • Toast Notifications
  • Client-side Validation
  • Clean Authentication Pages

⚙️ Tech Stack

TechnologyUsage
Next.js 16Full Stack Framework
React 19UI
TypeScriptType Safety
MongoDBDatabase
MongooseODM
JWTAuthentication
bcryptjsPassword Hashing
NodemailerEmail Service
AxiosHTTP Requests
Tailwind CSSStyling

📂 Project Structure

src
│
├── app
│ ├── api
│ │ └── users
│ │ ├── signup
│ │ ├── login
│ │ ├── logout
│ │ ├── me
│ │ ├── verifyemail
│ │ ├── forgotpassword
│ │ └── resetpassword
│ │
│ ├── login
│ ├── signup
│ ├── profile
│ ├── forgotpassword
│ ├── resetpassword
│ └── verifyemail
│
├── dbConfig
├── helpers
├── models
└── proxy.ts

🚀 Authentication Flow

User Signup
│
▼
Password Hashing (bcrypt)
│
▼
Store User in MongoDB
│
▼
Send Verification Email
│
▼
Verify Account
│
▼
Login
│
▼
Generate JWT
│
▼
Store JWT in HTTP-only Cookie
│
▼
Access Protected Routes

🔄 Password Recovery Flow

Forgot Password
│
▼
Generate Reset Token
│
▼
Send Reset Email
│
▼
User Opens Link
│
▼
Enter New Password
│
▼
Password Re-hashed
│
▼
Database Updated

🛠 Installation

Clone the repository

git clone https://github.com/othzer/Authentication-system-fullstack-nextjs.git

Install dependencies

npm install

Create an environment file

MONGO_URI=TOKEN_SECRET=DOMAIN=MAIL_HOST=MAIL_PORT=MAIL_USER=MAIL_PASS=

Run the development server

npm run dev

Open

http://localhost:3000

📌 API Endpoints

MethodEndpointDescription
POST/api/users/signupRegister User
POST/api/users/loginLogin User
GET/api/users/logoutLogout User
GET/api/users/meGet Logged-in User
POST/api/users/verifyemailVerify Email
POST/api/users/forgotpasswordSend Password Reset Email
POST/api/users/resetpasswordReset Password

🧠 What I Learned

This project helped strengthen my understanding of:

  • Authentication Architecture
  • JWT Authentication
  • HTTP-only Cookies
  • Password Hashing
  • Secure API Development
  • MongoDB with Mongoose
  • Next.js App Router
  • Email Verification Workflows
  • Password Recovery Systems
  • TypeScript Backend Development

🚀 Future Improvements

  • Google OAuth
  • GitHub OAuth
  • Refresh Tokens
  • Role-Based Access Control (RBAC)
  • Two-Factor Authentication (2FA)
  • Rate Limiting
  • Docker Support
  • Unit & Integration Tests
  • Account Management Dashboard
  • User Activity Logs

🤝 Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create your feature branch
git checkout -b feature/new-feature
  1. Commit your changes
git commit -m "Add new feature"
  1. Push your branch
git push origin feature/new-feature
  1. Open a Pull Request

📄 License

Proprietary — © OtzrLabs. All rights reserved.


⭐ If you found this project useful, consider giving it a Star!

It helps support future open-source projects and encourages continued development.

Made with ❤️ by OtzrLabs

About

Production-ready authentication system built with Next.js 16, TypeScript, MongoDB, JWT and secure email verification & password reset workflows.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages