A modern, full-stack blog platform built with Next.js 14, featuring authentication, protected routes, and a clean, responsive design. This project demonstrates core Next.js concepts including App Router, server components, and session management.
- User Authentication - Secure GitHub OAuth integration for seamless login
- Role-Based Access Control - Protected routes with admin and user roles
- Blog Management - Full CRUD operations for blog posts (admin only)
- Responsive Design - Mobile-first approach with modern UI/UX
- Session Management - Persistent user sessions with secure token handling
- Server & Client Components - Optimized rendering strategy
- Modern Stack - Built with Next.js 14 App Router and latest best practices
- Framework: Next.js 14 (App Router)
- Authentication: NextAuth.js with GitHub Provider
- Database: MongoDB with Mongoose ODM
- Styling: CSS Modules
- Deployment: Vercel (recommended)
Before you begin, ensure you have the following installed:
- Node.js 18.x or higher
- npm or yarn package manager
- MongoDB database (local or cloud)
- GitHub OAuth App credentials
- Clone the repository
git clone https://github.com/ram2005024/next14-starter.git
cd nextjs-blog- Install dependencies
npm install
# or
yarn install- Set up environment variables
Create a .env.local file in the root directory:
# MongoDB Connection
MONGODB_URI=your_mongodb_connection_string
# NextAuth Configuration
NEXTAUTH_SECRET=your_nextauth_secret_key
NEXTAUTH_URL=http://localhost:3000
# GitHub OAuth
GITHUB_ID=your_github_client_id
GITHUB_SECRET=your_github_client_secret- Run the development server
npm run dev
# or
yarn devOpen http://localhost:3000 in your browser.
- Go to GitHub Developer Settings
- Click "New OAuth App"
- Fill in the application details:
- Application name: Your Blog Name
- Homepage URL:
http://localhost:3000 - Authorization callback URL:
http://localhost:3000/api/auth/callback/github
- Copy the Client ID and generate a Client Secret
- Add them to your
.env.localfile
next14-starter/
├── src/
│ ├── app/
│ │ ├── components/ # Reusable components
│ │ │ ├── BlogCard/
│ │ │ ├── DeleteForm/
│ │ │ ├── Footer/
│ │ │ ├── Nav/
│ │ │ ├── Post/
│ │ │ ├── RegisterForm/
│ │ │ ├── SigninForm/
│ │ │ └── User/
│ │ ├── loading.jsx # Loading states
│ │ ├── not-found.jsx # 404 page
│ │ ├── page.jsx # Home page
│ │ └── page.module.css # Global styles
│ └── lib/
│ ├── action.js # Server actions
│ ├── auth.config.js # Auth configuration
│ ├── auth.js # Auth setup
│ ├── connectionToDB.js # Database connection
│ ├── data.js # Data fetching functions
│ ├── middleware.js # Route middleware
│ └── models.js # Mongoose models
├── .env.local # Environment variables
├── .eslintrc.json # ESLint configuration
├── .gitignore # Git ignore rules
├── jsconfig.json # JavaScript configuration
└── next.config.js # Next.js configuration
- User clicks "Sign in with GitHub"
- GitHub OAuth redirects to authorization page
- User authorizes the application
- Callback creates/updates user in database
- Session token is generated and stored
- User is redirected to the application
Admin-only routes are protected using middleware and session validation:
/admin/create-post- Create new blog posts/admin/manage-posts- Edit/delete existing posts
Regular users can:
- View all blog posts
- Read individual blog posts
- Access their profile
The application uses CSS Modules for component-scoped styling. Global styles are in page.module.css.
- Create new components in
src/app/components/ - Add server actions in
src/lib/action.js - Update data fetching in
src/lib/data.js - Define new models in
src/lib/models.js
- Push your code to GitHub
- Import your repository in Vercel
- Add environment variables in Vercel dashboard
- Update
NEXTAUTH_URLto your production URL - Update GitHub OAuth callback URL
- Deploy!
npm run build
npm startnpm run dev- Start development servernpm run build- Build for productionnpm start- Start production servernpm run lint- Run ESLint
Contributions are welcome! Please feel free to submit a Pull Request.
- 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.
- Special thanks to Lama Dev for the excellent tutorial that inspired this project
- Next.js team for the amazing framework
- Vercel for seamless deployment platform
Ram(Shekhar) Sharma -https://www.facebook.com/shekhar.sharma.390674/
Project Link: https://next14-starter-31as.vercel.app/
⭐ If you found this project helpful, please give it a star!