A food sharing platform where users can share and discover meals in their area. Now using MongoDB for authentication instead of Firebase.
- User Authentication: Secure login and registration with Firebase
- Food Post Sharing: Upload and share food photos with descriptions
- Real-time Messaging: Chat with other users about food
- User Profiles: Personalize your profile and view others
- Post Management: Create, edit, and delete your posts
- Responsive Design: Works on desktop and mobile devices
- React with TypeScript
- Firebase Authentication
- CSS for styling
- Node.js with Express
- MongoDB (with Mongoose)
- Cloudinary for image uploads
- Socket.io for real-time messaging
share-dish-main/
├── client/ # React frontend
│ ├── src/
│ │ ├── components/ # Reusable components
│ │ ├── contexts/ # React contexts
│ │ ├── pages/ # Page components
│ │ └── ...
├── server/ # Node.js backend
│ ├── controllers/ # Route controllers
│ ├── models/ # MongoDB models
│ ├── routes/ # API routes
│ ├── uploads/ # Uploaded images
│ └── ...
└── ...
- Node.js (v14 or higher)
- MongoDB Atlas account (free tier available)
-
Clone the repository
git clone <repository-url> cd share-dish-main
-
Install dependencies
# Install server dependencies cd server npm install # Install client dependencies cd ../client npm install
-
Set up MongoDB Atlas
- Create a free account at MongoDB Atlas
- Create a new cluster
- Get your connection string
-
Configure environment variables Create a
.envfile in theserverfolder:PORT=5000 MONGO_URI=your_mongodb_atlas_connection_string JWT_SECRET=your_secret_key_here
-
Start the application
# First of all: Go to PORTS in CodeSpace Right Click on *Backend(5000)* port Choose *Port Visibility* change it to *"Public"* # Start both server and client (from root directory) npm run dev # Or start them separately: # Terminal 1 - Server cd server npm run dev # Terminal 2 - Client cd client npm start
- Removed Firebase: No more Firebase Authentication
- MongoDB Authentication: Users are now stored and authenticated directly in MongoDB
- JWT Tokens: Using JSON Web Tokens for session management
- Password Hashing: Passwords are securely hashed using bcrypt
- ✅ User registration with MongoDB
- ✅ User login with JWT tokens
- ✅ Password change functionality
- ✅ Account deletion
- ✅ Secure password hashing
- ✅ Token-based authentication
// User Model
{
firstName: String (required),
lastName: String (required),
email: String (required, unique),
password: String (required, hashed),
gender: String (enum),
dateOfBirth: Date (required),
emailVerified: Boolean (default: false),
createdAt: Date (auto)
}POST /api/auth/register- Register new userPOST /api/auth/login- Login userPOST /api/auth/change-password- Change passwordPOST /api/auth/verify-password- Verify passwordPOST /api/auth/check-email- Check if email exists
GET /api/users/profile- Get current user profilePUT /api/users/profile- Update user profileDELETE /api/users/profile- Delete user account
GET /api/posts- Get all postsPOST /api/posts- Create new postPATCH /api/posts/:id- Update postDELETE /api/posts/:id- Delete postPATCH /api/posts/:id/reserve- Reserve post
share-dish-main/
├── client/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── contexts/ # React contexts
│ │ ├── pages/ # Page components
│ │ └── api.ts # API configuration
├── server/ # Node.js backend
│ ├── models/ # MongoDB models
│ ├── routes/ # API routes
│ ├── middleware/ # Custom middleware
│ └── app.js # Main server file
└── README.md
server/models/User.js- Updated user model with passwordserver/routes/auth.js- New authentication routesserver/middleware/auth.js- JWT authentication middlewareclient/src/contexts/AuthContext.tsx- Updated for MongoDB authclient/src/pages/Login.tsx- Updated login/register formsclient/src/api.ts- Added token handling
Make sure to set these environment variables in production:
MONGO_URI- Your MongoDB Atlas connection stringJWT_SECRET- A strong secret key for JWT tokensPORT- Server port (default: 5000)
- JWT tokens expire after 7 days
- Passwords are hashed using bcrypt with salt rounds of 10
- All sensitive routes require authentication
- CORS is configured for security
-
MongoDB Connection Failed
- Check your connection string
- Ensure your IP is whitelisted in MongoDB Atlas
- Verify network connectivity
-
JWT Token Issues
- Check that JWT_SECRET is set
- Ensure tokens are being sent in Authorization header
-
Password Issues
- Passwords must be at least 6 characters with at least one number
- Check that bcrypt is properly installed
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Note: This version uses MongoDB for authentication instead of Firebase, providing more control over user data and authentication flow.
- Mohamed Sadek
- Mohamed Nouh
- Hesham Elmogy