A simple MERN stack application with authentication and user dashboard.
- User registration and login
- JWT-based authentication
- Protected dashboard route
- User profile display
- MongoDB database integration
- Node.js (v14 or higher)
- MongoDB (running locally or a MongoDB Atlas account)
- npm or yarn
.
├── backend/ # Node.js/Express backend
│ ├── src/
│ │ ├── models/ # MongoDB models
│ │ ├── routes/ # API routes
│ │ └── index.js # Main server file
│ └── package.json
└── frontend/ # Next.js frontend
├── pages/ # Next.js pages
└── package.json
-
Navigate to the backend directory:
cd backend -
Install dependencies:
npm install
-
Create a
.envfile in the backend directory with the following content:PORT=5000 MONGODB_URI=mongodb://localhost:27017/auth-dashboard JWT_SECRET=your-super-secret-key-change-this-in-production -
Start the backend server:
npm run dev
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the frontend development server:
npm run dev
- Open your browser and navigate to
http://localhost:3000 - Create a new account using the signup form
- Log in with your credentials
- View your profile information on the dashboard
POST /api/auth/signup- Register a new userPOST /api/auth/login- Login userGET /api/auth/profile- Get user profile (requires authentication)
This application is ready to be dockerized. You can create Dockerfiles for both frontend and backend services, and use Docker Compose to orchestrate them along with MongoDB.
- Change the JWT_SECRET in production
- Use environment variables for sensitive data
- Implement rate limiting in production
- Add input validation and sanitization
- Use HTTPS in production