Skip to content

Repository files navigation

🔐 Auth.js v5 Next.js Authentication Project

Next.jsTypeScriptMongoDBAuth.js

A comprehensive authentication solution built with Next.js and Auth.js v5, featuring multiple sign-in methods and MongoDB integration.

📋 Table of Contents

🌟 Overview

This project demonstrates a modern authentication implementation using Auth.js v5 in a Next.js application. It provides a secure and scalable solution for handling user authentication with various providers and MongoDB integration.

✨ Features

  • 🔒 Secure authentication with Auth.js v5
  • 🚀 Built with Next.js 14+ and TypeScript
  • 📱 Social login integration:
    • Google Sign-In
    • GitHub Authentication
  • 💾 MongoDB database integration
  • 🎨 Styled with Tailwind CSS
  • 🔐 Protected routes and middleware
  • 📱 Responsive design

🔧 Prerequisites

Before getting started, ensure you have the following installed:

  • Node.js (v18 or higher)
  • npm or yarn package manager
  • MongoDB Atlas account or local MongoDB installation
  • Git

🚀 Installation

  1. Clone the repository:
git clone https://github.com/arsath-eng/Auth-Testing.git
  1. Navigate to the project directory:
cd auth-project
  1. Install dependencies:
npm install
# or
yarn install

📁 Project Structure

AUTH-PROJECT/
├── 📂 .next/ # Next.js build output
├── 📂 action/ # Server actions
├── 📂 app/ # Next.js app directory
│ ├── api/ # API routes
│ ├── auth/ # Authentication pages
│ └── ... # Other app routes
├── 📂 components/ # Reusable React components
├── 📂 lib/ # Utility functions and configurations
│ ├── db.ts # Database connection
│ ├── getSession.ts # Session management
│ └── utils.ts # Helper functions
├── 📂 models/ # MongoDB models
│ └── User.ts # User model definition
├── 📂 public/ # Static assets
├── 📄 .env # Environment variables
├── 📄 auth.ts # Auth.js configuration
├── 📄 middleware.ts # Next.js middleware
└── 📄 [Other config files] # Various configuration files

⚙️ Configuration

  1. Create a .env file in the root directory with the following variables:
# MongoDB ConnectionMONGO_URI='mongodb+srv://your-connection-string'# Auth.js SecretAUTH_SECRET='your-secret-key'# GitHub OAuthGITHUB_CLIENT_ID='your-github-client-id'GITHUB_CLIENT_SECRET='your-github-client-secret'# Google OAuthGOOGLE_CLIENT_ID='your-google-client-id'GOOGLE_CLIENT_SECRET='your-google-client-secret'
  1. Configure OAuth Providers:

🚀 Running the Project

  1. Start the development server:
npm run dev
# or
yarn dev
  1. Open your browser and navigate to:
http://localhost:3000

📸 Screenshots

admin

register

user

mongodb

```

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ by Arsath

About

A comprehensive authentication solution that demonstrates best practices for implementing user authentication in Next.js applications. Features include social login with Google and GitHub, MongoDB integration for user management, protected routes, and a responsive UI built with Tailwind CSS.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages