A comprehensive authentication solution built with Next.js and Auth.js v5, featuring multiple sign-in methods and MongoDB integration.
- Overview
- Features
- Prerequisites
- Installation
- Project Structure
- Configuration
- Running the Project
- Screenshots
- Contributing
- License
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.
- 🔒 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
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
- Clone the repository:
git clone https://github.com/arsath-eng/Auth-Testing.git
- Navigate to the project directory:
cd auth-project
- Install dependencies:
npm install
# or
yarn install
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
- Create a
.env
file in the root directory with the following variables:
# MongoDB Connection
MONGO_URI='mongodb+srv://your-connection-string'
# Auth.js Secret
AUTH_SECRET='your-secret-key'
# GitHub OAuth
GITHUB_CLIENT_ID='your-github-client-id'
GITHUB_CLIENT_SECRET='your-github-client-secret'
# Google OAuth
GOOGLE_CLIENT_ID='your-google-client-id'
GOOGLE_CLIENT_SECRET='your-google-client-secret'
- Configure OAuth Providers:
- Set up OAuth applications in GitHub Developer Settings
- Configure OAuth consent in Google Cloud Console
- Start the development server:
npm run dev
# or
yarn dev
- Open your browser and navigate to:
http://localhost:3000
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by Arsath