A modern, full-featured blog built with Next.js, Tailwind CSS, and MongoDB.
- 🔐 Authentication with NextAuth (Credentials, GitHub, Google)
- 📝 Full-featured blog with posts, comments, and categories
- 👤 User profiles and admin dashboard
- 🌓 Dark/light theme support
- 📱 Responsive design with Tailwind CSS and DaisyUI
- 🚀 Fast and SEO-friendly with Next.js
-
Clone the repository:
git clone https://github.com/yourusername/blog.git cd blog -
Install dependencies:
npm install -
Create
.envfile in the root directory:# Database DATABASE_URL="mongodb+srv://yourusername:[email protected]/blog?retryWrites=true&w=majority" # Authentication NEXTAUTH_SECRET="your-nextauth-secret-key-should-be-at-least-32-chars" NEXTAUTH_URL="http://localhost:3000" # OAuth providers (optional) GITHUB_ID="your-github-client-id" GITHUB_SECRET="your-github-client-secret" GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret" -
Initialize the database:
npm run db:push -
Seed the database with sample data:
npm run seed -
Start the development server:
npm run dev -
Access the blog at http://localhost:3000
If you experience issues with OAuth authentication:
- Make sure your callback URLs are correctly set up in the provider's developer console
- For GitHub:
http://localhost:3000/api/auth/callback/github(for local development) - For Google:
http://localhost:3000/api/auth/callback/google(for local development) - Check that the client ID and secret are correctly configured in your
.envfile
If you can't connect to MongoDB:
- Ensure your MongoDB connection string includes the database name (
/blogin the URL) - Check that your IP address is whitelisted in MongoDB Atlas Network Access settings
- Verify that your database username and password are correct
- Try running
npm run db:pushto see specific error messages
-
Create a new Replit using "Import from GitHub"
-
Add environment variables in the "Secrets" panel:
DATABASE_URL: Your MongoDB connection stringNEXTAUTH_SECRET: A random string for encryptionNEXTAUTH_URL: Your Replit URLGITHUB_IDandGITHUB_SECRET: For GitHub auth (optional)GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRET: For Google auth (optional)
-
Install dependencies and set up the database:
npm install npm run db:push npm run seed -
Run the blog:
npm run build npm start
- Create a free MongoDB Atlas account
- Create a new cluster and choose the free tier
- In "Network Access," add
0.0.0.0/0to allow connections from anywhere - In "Database Access," create a database user with password authentication
- On your cluster, click "Connect" → "Connect your application" and copy the connection string
- Replace the placeholders in your connection string with your actual username and password
- Go to GitHub Developer Settings
- Create a new OAuth App
- Set the Homepage URL to your Replit URL or http://localhost:3000
- Set the Authorization callback URL to your Replit URL + "/api/auth/callback/github" or "http://localhost:3000/api/auth/callback/github"
- Go to the Google Cloud Console
- Create a new project
- Go to "APIs & Services" → "Credentials"
- Configure the OAuth consent screen
- Create OAuth client ID credentials
- Set Authorized JavaScript origins to your Replit URL or http://localhost:3000
- Set Authorized redirect URIs to your Replit URL + "/api/auth/callback/google" or "http://localhost:3000/api/auth/callback/google"
After running the seed script, you can log in with:
- Email: [email protected]
- Password: admin123