A instagram clone built with Next.js, MongoDB, and NextAuth.js.
- User authentication (login/register) with:
- Email and password
- GitHub OAuth
- Google OAuth
- MongoDB integration
- AWS S3 for image storage
- Post creation with image uploads
- Dark theme UI
- Responsive design
- Node.js 18+
- Docker and Docker Compose
- AWS account (for S3 image storage)
- Clone the repository
git clone <repository-url>
cd instagram-clone- Install dependencies
npm install- Set up environment variables
Copy the example environment file and update the values:
cp .env.example .env.localYou'll need to set up:
- OAuth applications for GitHub and Google
- AWS S3 bucket for image storage
- MongoDB connection (or use the provided Docker setup)
- Start MongoDB with Docker Compose
docker-compose up -d- Run the development server
npm run devOpen http://localhost:3000 in your browser.
The app uses NextAuth.js for authentication with the following providers:
- Credentials (username/password)
- GitHub
To configure OAuth providers:
- Create OAuth applications on GitHub and Google
- Add the credentials to your
.env.localfile - Set the callback URL to
http://localhost:3000/api/auth/callback/{provider}where{provider}is eithergithuborgoogle
This application uses AWS S3 for storing images. Follow these steps to set up your S3 bucket:
-
Create an AWS account if you don't have one already
-
Create an S3 bucket:
- Sign in to the AWS Management Console
- Navigate to the S3 service
- Click "Create bucket"
- Choose a unique bucket name
- Select a region close to your users
- Configure bucket settings (you can leave defaults for testing)
- Create the bucket
-
Configure CORS for your bucket:
- Select your bucket
- Go to the "Permissions" tab
- Scroll down to "Cross-origin resource sharing (CORS)"
- Add the following CORS configuration:
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"AllowedOrigins": ["http://localhost:3000"],
"ExposeHeaders": []
}
]- Create an IAM user with S3 access:
- Navigate to the IAM service
- Go to "Users" and click "Add user"
- Choose a username (e.g., "instagram-clone-s3")
- Select "Programmatic access"
- Create a policy with the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"
}
]
}- Get your access keys:
- After creating the user, you'll be shown an Access Key ID and Secret Access Key
- Add these to your
.env.localfile:
AWS_REGION=your-selected-region
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_S3_BUCKET_NAME=your-bucket-name
/src/app: Next.js app router/src/components: React components/src/lib: Utility functions/src/models: MongoDB models
The project includes a Docker setup for MongoDB. To start the database:
docker-compose up -dThis will start a MongoDB instance on port 27017 with the credentials specified in the .env file.
This project is licensed under the MIT License.