├── client └── my-app │ ├── src │ ├── index.css │ ├── setupTests.js │ ├── App.test.js │ ├── components │ │ ├── PrivateComponent.js │ │ ├── Login.js │ │ ├── ForgotPassword.js │ │ ├── Navbar.js │ │ ├── Register.js │ │ ├── likedProducts.js │ │ ├── AddRecipe.js │ │ └── Recipes.js │ ├── styles │ │ ├── Searchbar.css │ │ ├── ForgotPassword.css │ │ ├── Addrecipe.css │ │ ├── likedProducts.css │ │ └── RecipeStyle.css │ ├── reportWebVitals.js │ ├── index.js │ ├── App.js │ ├── logo.svg │ └── App.css │ ├── netlify.toml │ ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── index.html │ ├── .gitignore │ ├── package.json │ └── README.md ├── public └── static │ └── images │ ├── website1.png │ ├── website2.png │ ├── website3.png │ └── website4.png ├── server ├── controllers │ ├── controller.js │ ├── RegisterController.js │ ├── LoginController.js │ ├── ForgotPasswordController.js │ └── RecipeController.js ├── routes │ ├── forgotPassword.js │ ├── LoginRoute.js │ ├── RecipeRoute.js │ └── RegisterRoute.js ├── Schema │ ├── UserSchema.js │ ├── RecipeSchema.js │ └── LikedRecipeSchema.js ├── db │ └── config.js ├── package.json ├── Middleware │ └── middleware.js ├── index.js └── package-lock.json ├── .gitignore └── readme.md /client/my-app/src/index.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/my-app/netlify.toml: -------------------------------------------------------------------------------- 1 | [[redirects]] 2 | from = "/*" 3 | to = "/index.html" 4 | status = 200 -------------------------------------------------------------------------------- /client/my-app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /client/my-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/client/my-app/public/favicon.ico -------------------------------------------------------------------------------- /client/my-app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/client/my-app/public/logo192.png -------------------------------------------------------------------------------- /client/my-app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/client/my-app/public/logo512.png -------------------------------------------------------------------------------- /public/static/images/website1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/public/static/images/website1.png -------------------------------------------------------------------------------- /public/static/images/website2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/public/static/images/website2.png -------------------------------------------------------------------------------- /public/static/images/website3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/public/static/images/website3.png -------------------------------------------------------------------------------- /public/static/images/website4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rohith-Manjunath/MERN-Recipe-App/HEAD/public/static/images/website4.png -------------------------------------------------------------------------------- /server/controllers/controller.js: -------------------------------------------------------------------------------- 1 | exports.Home = (req, res) => { 2 | const user = req.token; 3 | 4 | res.status(200).json({ message: `Home` }); 5 | }; 6 | -------------------------------------------------------------------------------- /server/routes/forgotPassword.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const ForgotPassword = require("../controllers/ForgotPasswordController.js"); 4 | 5 | router.put("/forgotpassword", ForgotPassword); 6 | 7 | module.exports = router; 8 | -------------------------------------------------------------------------------- /server/Schema/UserSchema.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const UserSchema = mongoose.Schema({ 4 | name: String, 5 | password: String, 6 | email: { type: String, lowercase: true }, 7 | }); 8 | 9 | module.exports = mongoose.model("User", UserSchema); 10 | -------------------------------------------------------------------------------- /client/my-app/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /server/db/config.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | mongoose 3 | .connect(process.env.URI) 4 | .then(() => { 5 | console.log("Connected to the database"); 6 | }) 7 | .catch((error) => { 8 | console.error("Error connecting to the database:", error); 9 | }); 10 | -------------------------------------------------------------------------------- /client/my-app/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /client/my-app/src/components/PrivateComponent.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Outlet, Navigate } from "react-router-dom"; 3 | 4 | const PrivateComponent = () => { 5 | const auth = localStorage.getItem("token"); 6 | 7 | return auth ? : ; 8 | }; 9 | 10 | export default PrivateComponent; 11 | -------------------------------------------------------------------------------- /client/my-app/src/styles/Searchbar.css: -------------------------------------------------------------------------------- 1 | 2 | .search-bar { 3 | margin-bottom: 20px; 4 | height: 50px; 5 | margin-top: 2rem; 6 | 7 | } 8 | 9 | .search-bar input { 10 | width: 100%; 11 | padding: 10px; 12 | height: 100%; 13 | font-size: 16px; 14 | border: 1px solid #ccc; 15 | border-radius: 5px; 16 | outline: none; 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /server/Schema/RecipeSchema.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const recipeSchema = new mongoose.Schema({ 4 | title: { 5 | type: String, 6 | required: true, 7 | }, 8 | ingredients: [String], 9 | instructions: { 10 | type: String, 11 | required: true, 12 | }, 13 | imageUrl: String, 14 | }); 15 | 16 | const Recipe = mongoose.model("Recipe", recipeSchema); 17 | 18 | module.exports = Recipe; 19 | -------------------------------------------------------------------------------- /client/my-app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /server/Schema/LikedRecipeSchema.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const LikedRecipes = new mongoose.Schema({ 4 | title: { 5 | type: String, 6 | required: true, 7 | }, 8 | ingredients: [String], 9 | instructions: { 10 | type: String, 11 | required: true, 12 | }, 13 | imageUrl: String, 14 | }); 15 | 16 | const Liked = mongoose.model("LikedRecipe", LikedRecipes); 17 | 18 | module.exports = Liked; 19 | -------------------------------------------------------------------------------- /client/my-app/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "server", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "dev": "node index", 9 | "start": "nodemon index" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "dependencies": { 15 | "bcrypt": "^5.1.1", 16 | "cors": "^2.8.5", 17 | "dotenv": "^16.3.1", 18 | "express": "^4.18.2", 19 | "jsonwebtoken": "^9.0.2", 20 | "mongoose": "^7.5.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /server/Middleware/middleware.js: -------------------------------------------------------------------------------- 1 | const jwt = require("jsonwebtoken"); 2 | 3 | function verifyToken(req, res, next) { 4 | const token = req.header("Authorization"); 5 | 6 | if (!token) { 7 | return res 8 | .status(401) 9 | .json({ message: "Access denied. No token provided." }); 10 | } 11 | 12 | try { 13 | const decoded = jwt.verify(token, process.env.SECRET); 14 | req.token = decoded; 15 | next(); 16 | } catch (error) { 17 | res.status(403).json({ message: "Invalid token." }); 18 | } 19 | } 20 | 21 | module.exports = verifyToken; 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node.js / NPM 2 | node_modules/ 3 | npm-debug.log 4 | yarn-error.log 5 | 6 | # React build output 7 | /build 8 | /dist 9 | 10 | # IDE and editor-specific files (Optional, depending on your IDE/editor) 11 | .vscode/ 12 | .idea/ 13 | *.sublime-project 14 | *.sublime-workspace 15 | 16 | # macOS specific files (Optional, depending on the OS used by your team) 17 | .DS_Store 18 | 19 | # Environment files (Optional, depending on your setup) 20 | .env 21 | .env.local 22 | .env.development.local 23 | .env.test.local 24 | .env.production.local 25 | 26 | # Local Netlify folder 27 | .netlify 28 | -------------------------------------------------------------------------------- /client/my-app/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /client/my-app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /server/routes/LoginRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const jwt = require("jsonwebtoken"); 4 | const LoginController = require("../controllers/LoginController"); 5 | 6 | router.post("/login", LoginController); 7 | function verifyToken(req, res, next) { 8 | const token = req.header("Authorization"); 9 | 10 | if (!token) { 11 | return res 12 | .status(401) 13 | .json({ message: "Access denied. No token provided." }); 14 | } 15 | 16 | try { 17 | const decoded = jwt.verify(token, process.env.SECRET); 18 | req.token = decoded; 19 | next(); 20 | } catch (error) { 21 | res.status(403).json({ message: "Invalid token." }); 22 | } 23 | } 24 | 25 | module.exports = router; 26 | -------------------------------------------------------------------------------- /server/routes/RecipeRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const verifyToken = require("../Middleware/middleware"); 4 | 5 | const { 6 | getAllRecipes, 7 | createRecipe, 8 | deleteRecipe, 9 | LikedList, 10 | getAllLikedRecipes, 11 | removeFromLikedRecipes, 12 | searchRecipes, 13 | } = require("../controllers/RecipeController"); 14 | 15 | router.post("/recipe", createRecipe); 16 | router.get("/recipe", verifyToken, getAllRecipes); 17 | router.get("/likedRecipes", getAllLikedRecipes); 18 | router.delete("/recipe/:id", deleteRecipe); 19 | router.post("/likedRecipes/:id", LikedList); 20 | router.delete("/removeLiked/:id", removeFromLikedRecipes); 21 | router.get("/searchRecipes/:key", searchRecipes); 22 | 23 | module.exports = router; 24 | -------------------------------------------------------------------------------- /server/controllers/RegisterController.js: -------------------------------------------------------------------------------- 1 | const User = require("../Schema/UserSchema"); 2 | const bcrypt = require("bcrypt"); 3 | const jwt = require("jsonwebtoken"); 4 | 5 | const Register = async (req, res) => { 6 | try { 7 | const { name, email, password } = req.body; 8 | const user = await User.findOne({ email }); 9 | 10 | if (user) { 11 | return res.json({ error: "User already exists" }); 12 | } 13 | 14 | const token = jwt.sign(email, process.env.SECRET); 15 | const hash = await bcrypt.hash(password, 10); 16 | const newUser = await User.create({ name, email, password: hash }); 17 | res.json({ newUser, token }); 18 | } catch (e) { 19 | console.error(e.message); 20 | res.status(500).json({ error: "Internal server error" }); 21 | } 22 | }; 23 | 24 | module.exports = Register; 25 | -------------------------------------------------------------------------------- /server/routes/RegisterRoute.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const router = express.Router(); 3 | const bcrypt = require("bcrypt"); 4 | const jwt = require("jsonwebtoken"); 5 | const User = require("../Schema/UserSchema"); 6 | const RegisterController = require("../controllers/RegisterController"); 7 | 8 | router.post("/register", RegisterController); 9 | 10 | function verifyToken(req, res, next) { 11 | const token = req.header("Authorization"); 12 | 13 | if (!token) { 14 | return res 15 | .status(401) 16 | .json({ message: "Access denied. No token provided." }); 17 | } 18 | 19 | try { 20 | const decoded = jwt.verify(token, process.env.SECRET); 21 | req.token = decoded; 22 | next(); 23 | } catch (error) { 24 | res.status(403).json({ message: "Invalid token." }); 25 | } 26 | } 27 | 28 | module.exports = router; 29 | -------------------------------------------------------------------------------- /server/controllers/LoginController.js: -------------------------------------------------------------------------------- 1 | const User = require("../Schema/UserSchema"); 2 | const bcrypt = require("bcrypt"); 3 | const jwt = require("jsonwebtoken"); 4 | const Login = async (req, res) => { 5 | try { 6 | const { email, password } = req.body; 7 | const user = await User.findOne({ email }); 8 | 9 | if (!user) { 10 | return res.status(401).json({ error: "User not found" }); 11 | } 12 | 13 | const passwordMatch = await bcrypt.compare(password, user.password); 14 | 15 | if (!passwordMatch) { 16 | return res.status(401).json({ error: "Incorrect password" }); 17 | } 18 | 19 | const token = jwt.sign( 20 | { email: user.email, _id: user._id }, 21 | process.env.SECRET 22 | ); 23 | 24 | res.json({ 25 | token, 26 | user: { _id: user._id, name: user.name, email: user.email }, 27 | }); 28 | } catch (e) { 29 | console.error(e.message); 30 | res.status(500).json({ error: "Internal server error" }); 31 | } 32 | }; 33 | 34 | module.exports = Login; 35 | -------------------------------------------------------------------------------- /server/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const app = express(); 3 | const cors = require("cors"); 4 | const bcrypt = require("bcrypt"); 5 | const jwt = require("jsonwebtoken"); 6 | const dotenv = require("dotenv"); 7 | dotenv.config(); 8 | const router = express.Router(); 9 | 10 | app.use(express.json()); 11 | app.use(cors()); 12 | 13 | const config = require("./db/config"); 14 | const Home = require("./controllers/controller"); 15 | const LoginRoute = require("./routes/LoginRoute"); 16 | const RegisterRoute = require("./routes/RegisterRoute"); 17 | const verifyToken = require("./Middleware/middleware"); 18 | const RecipeRoute = require("./routes/RecipeRoute"); 19 | const ForgotPassword = require("./routes/forgotPassword"); 20 | 21 | app.use("/auth", LoginRoute); 22 | app.use("/auth", RegisterRoute); 23 | app.use("/auth", RecipeRoute); 24 | app.use("/auth", router); 25 | app.use("/auth", ForgotPassword); 26 | 27 | router.get("/", verifyToken, Home.Home); 28 | 29 | module.exports = router; 30 | 31 | if (config) { 32 | app.listen(process.env.PORT, () => { 33 | console.log(`Server Started on port ${process.env.PORT}`); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /server/controllers/ForgotPasswordController.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require("bcrypt"); 2 | const User = require("../Schema/UserSchema"); 3 | 4 | const ForgotPassword = async (req, res) => { 5 | const { email, password } = req.body; 6 | 7 | try { 8 | // Check if a user with the provided email exists 9 | const user = await User.findOne({ email }); 10 | 11 | if (user) { 12 | // Hash the new password before updating it 13 | const hashedPassword = await bcrypt.hash(password, 10); 14 | 15 | // Update the user's password in the database 16 | user.password = hashedPassword; 17 | await user.save(); 18 | 19 | // Respond with a success message 20 | res.status(200).json({ message: "Password updated successfully" }); 21 | } else { 22 | // If no user is found with the given email 23 | res 24 | .status(404) 25 | .json({ message: "No user found with this email address" }); 26 | } 27 | } catch (error) { 28 | // Handle unexpected errors 29 | console.error(error); 30 | res.status(500).json({ message: "Internal server error" }); 31 | } 32 | }; 33 | 34 | module.exports = ForgotPassword; 35 | -------------------------------------------------------------------------------- /client/my-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@fortawesome/fontawesome-svg-core": "^6.4.2", 7 | "@fortawesome/free-solid-svg-icons": "^6.4.2", 8 | "@fortawesome/react-fontawesome": "^0.2.0", 9 | "@testing-library/jest-dom": "^5.17.0", 10 | "@testing-library/react": "^13.4.0", 11 | "@testing-library/user-event": "^13.5.0", 12 | "react": "^18.2.0", 13 | "react-dom": "^18.2.0", 14 | "react-router-dom": "^6.16.0", 15 | "react-scripts": "5.0.1", 16 | "react-toastify": "^9.1.3", 17 | "toastify": "^2.0.1", 18 | "web-vitals": "^2.1.4" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": [ 28 | "react-app", 29 | "react-app/jest" 30 | ] 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /client/my-app/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import Login from "./components/Login"; 3 | import { Routes, Route, BrowserRouter as Router } from "react-router-dom"; 4 | import Register from "./components/Register"; 5 | import Navbar from "./components/Navbar"; 6 | import PrivateComponent from "./components/PrivateComponent"; 7 | import Recipes from "./components/Recipes"; 8 | import AddRecipe from "./components/AddRecipe"; 9 | import LikedProducts from "./components/likedProducts"; 10 | import ForgotPassword from "./components/ForgotPassword"; 11 | 12 | function App() { 13 | return ( 14 | 15 | 16 | 17 | 18 | } /> 19 | } /> 20 | } /> 21 | 22 | }> 23 | } /> 24 | } /> 25 | } /> 26 | } /> 27 | 28 | 29 | 30 | ); 31 | } 32 | 33 | export default App; 34 | -------------------------------------------------------------------------------- /client/my-app/src/styles/ForgotPassword.css: -------------------------------------------------------------------------------- 1 | /* UpdatePassword Component Styles */ 2 | 3 | /* Main container styles */ 4 | .update-password-container { 5 | max-width: 400px; 6 | margin: 0 auto; 7 | padding: 20px; 8 | border: 1px solid #ccc; 9 | border-radius: 5px; 10 | background-color: #f9f9f9; 11 | box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); 12 | margin-top: 15rem; 13 | 14 | } 15 | 16 | /* Heading styles */ 17 | .update-password-container h2 { 18 | text-align: center; 19 | margin-bottom: 20px; 20 | } 21 | 22 | /* Form field styles */ 23 | .form-group { 24 | margin-bottom: 20px; 25 | } 26 | 27 | .form-group label { 28 | font-weight: bold; 29 | margin-bottom: 5px; 30 | } 31 | 32 | .form-group input[type="email"], 33 | .form-group input[type="password"] { 34 | width: 100%; 35 | padding: 10px; 36 | border: 1px solid #ccc; 37 | border-radius: 5px; 38 | font-size: 16px; 39 | } 40 | 41 | /* Submit button styles */ 42 | .update-password-container button { 43 | display: block; 44 | width: 100%; 45 | padding: 10px; 46 | background-color: #007bff; 47 | color: white; 48 | border: none; 49 | border-radius: 5px; 50 | font-size: 16px; 51 | cursor: pointer; 52 | } 53 | 54 | .update-password-container button:hover { 55 | background-color: #0056b3; 56 | } 57 | 58 | /* Error message styles */ 59 | .error-message { 60 | margin-top: 10px; 61 | color: #ff0000; 62 | font-weight: bold; 63 | text-align: center; 64 | } 65 | -------------------------------------------------------------------------------- /client/my-app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /client/my-app/src/styles/Addrecipe.css: -------------------------------------------------------------------------------- 1 | /* AddRecipe.css */ 2 | 3 | .add-recipe { 4 | 5 | max-width: 600px; 6 | margin: 0 auto; 7 | padding: 20px; 8 | border: 1px solid #ccc; 9 | border-radius: 5px; 10 | background-color: #fff; 11 | box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); 12 | margin-top: 6rem; 13 | } 14 | 15 | .add-recipe h2 { 16 | font-size: 24px; 17 | margin-bottom: 20px; 18 | color: #333; 19 | } 20 | 21 | .add-recipe form { 22 | display: flex; 23 | flex-direction: column; 24 | } 25 | 26 | .add-recipe label { 27 | font-weight: bold; 28 | margin-bottom: 5px; 29 | color: #333; 30 | } 31 | 32 | .add-recipe input[type="text"], 33 | .add-recipe textarea { 34 | padding: 10px; 35 | margin-bottom: 15px; 36 | border: 1px solid #ccc; 37 | border-radius: 3px; 38 | font-size: 16px; 39 | } 40 | 41 | .add-recipe input[type="text"] { 42 | width: 100%; 43 | } 44 | 45 | .add-recipe textarea { 46 | width: 100%; 47 | height: 150px; 48 | } 49 | 50 | .add-recipe button[type="submit"], 51 | .add-recipe button[type="button"] { 52 | background-color: #007bff; 53 | color: #fff; 54 | padding: 10px 20px; 55 | border: none; 56 | border-radius: 3px; 57 | font-size: 16px; 58 | cursor: pointer; 59 | } 60 | 61 | .add-recipe button[type="button"] { 62 | background-color: #28a745; 63 | } 64 | 65 | .add-recipe button[type="submit"]:hover, 66 | .add-recipe button[type="button"]:hover { 67 | background-color: #0056b3; 68 | } 69 | 70 | /* Additional styling for ingredient inputs */ 71 | .add-recipe .ingredient-inputs { 72 | display: flex; 73 | flex-direction: column; 74 | } 75 | 76 | .add-recipe .ingredient-inputs input[type="text"] { 77 | width: 100%; 78 | margin-bottom: 10px; 79 | } 80 | 81 | .add-recipe .ingredient-inputs button { 82 | align-self: flex-start; 83 | background-color: #ffc107; 84 | } 85 | 86 | .add-recipe .ingredient-inputs button:hover { 87 | background-color: #ff9800; 88 | } 89 | 90 | @media (min-width: 320px) and (max-width: 480px) { 91 | .add-recipe { 92 | margin-top: 5rem; 93 | } 94 | } -------------------------------------------------------------------------------- /client/my-app/src/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import "../App.css"; 3 | import { Link } from "react-router-dom"; 4 | import { ToastContainer, toast } from "react-toastify"; 5 | import "react-toastify/dist/ReactToastify.css"; // Import the CSS for styling 6 | 7 | const Login = () => { 8 | const [email, setEmail] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [showError, setShowError] = useState(false); 11 | const Email = email.toLowerCase(); 12 | const handleSubmit = async (e) => { 13 | e.preventDefault(); 14 | 15 | if (!email || !password) { 16 | setShowError(true); 17 | return; 18 | } 19 | 20 | try { 21 | let response = await fetch( 22 | "https://recipe-app-mern.onrender.com/auth/login", 23 | { 24 | method: "POST", 25 | headers: { "Content-Type": "application/json" }, 26 | body: JSON.stringify({ email: Email, password }), 27 | } 28 | ); 29 | 30 | response = await response.json(); 31 | 32 | if (!response.error) { 33 | toast.success("Login Successful"); 34 | localStorage.setItem("token", response.token); 35 | 36 | setTimeout(() => { 37 | window.location.href = "/"; 38 | }, 4000); 39 | } else { 40 | toast.error(response.error); 41 | } 42 | } catch (error) { 43 | console.error("An error occurred while registering user:", error); 44 | } 45 | }; 46 | 47 | return ( 48 |
49 |
handleSubmit(e)}> 50 |

Login

51 | 52 | setEmail(e.target.value)} 56 | /> 57 | setPassword(e.target.value)} 61 | /> 62 | 63 | 64 | Forgot Password 65 |
66 | {showError && ( 67 | Please Fill all the fields 68 | )} 69 | 70 |
71 | ); 72 | }; 73 | 74 | export default Login; 75 | -------------------------------------------------------------------------------- /client/my-app/src/styles/likedProducts.css: -------------------------------------------------------------------------------- 1 | /* LikedProducts.css */ 2 | 3 | .likedRecipes { 4 | max-width: 800px; 5 | margin: 0 auto; 6 | padding: 20px; 7 | background-color: #f5f5f5; 8 | border-radius: 10px; 9 | box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); 10 | margin-top: 8rem !important; 11 | 12 | } 13 | 14 | .likedRecipes h2 { 15 | font-size: 24px; 16 | margin-bottom: 20px; 17 | } 18 | 19 | .likedRecipes ul { 20 | list-style-type: none; 21 | padding: 0; 22 | } 23 | 24 | .likedRecipes .list { 25 | margin-bottom: 30px; 26 | background-color: #fff; 27 | padding: 20px; 28 | border: 1px solid #ddd; 29 | border-radius: 5px; 30 | box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); 31 | } 32 | 33 | .likedRecipes h3 { 34 | font-size: 20px; 35 | margin-bottom: 10px; 36 | color: #333; 37 | } 38 | 39 | .likedRecipes p { 40 | font-size: 16px; 41 | color: #777; 42 | margin-bottom: 10px; 43 | } 44 | 45 | .likedRecipes img { 46 | max-width: 100%; 47 | height: auto; 48 | margin-top: 20px; 49 | border-radius: 5px; 50 | box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2); 51 | } 52 | 53 | .likedRecipes h4 { 54 | font-size: 18px; 55 | margin-top: 20px; 56 | } 57 | 58 | .likedRecipes ul.liked-product-ingredients { 59 | list-style-type: disc; 60 | margin-left: 20px; 61 | } 62 | 63 | .likedRecipes ul.liked-product-ingredients li { 64 | font-size: 16px; 65 | } 66 | 67 | .likedRecipes ol.liked-product-instructions { 68 | list-style-type: decimal; 69 | margin-left: 20px; 70 | } 71 | 72 | .likedRecipes ol.liked-product-instructions li { 73 | font-size: 16px; 74 | } 75 | 76 | 77 | 78 | /* RecipeStyle.css */ 79 | 80 | /* Add styles for the remove item button */ 81 | .remove-item-button { 82 | background-color: #ff5c5c; /* Red background color */ 83 | color: white; /* White text color */ 84 | border: none; 85 | padding: 10px 20px; 86 | margin-right: 10px; 87 | cursor: pointer; 88 | border-radius: 5px; 89 | font-size: 16px; 90 | transition: background-color 0.3s ease; 91 | 92 | /* Hover effect */ 93 | &:hover { 94 | background-color: #ff0000; /* Darker red on hover */ 95 | } 96 | } 97 | 98 | .instructions-list li { 99 | margin-bottom: 8px; /* Adjust the value as needed to control the spacing */ 100 | } 101 | -------------------------------------------------------------------------------- /client/my-app/src/components/ForgotPassword.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import "../styles/ForgotPassword.css"; 3 | import { toast, ToastContainer } from "react-toastify"; 4 | 5 | const UpdatePassword = () => { 6 | const [formData, setFormData] = useState({ 7 | email: "", 8 | password: "", 9 | }); 10 | const [message, setMessage] = useState(null); 11 | 12 | const handleChange = (e) => { 13 | const { name, value } = e.target; 14 | setFormData({ ...formData, [name]: value }); 15 | }; 16 | 17 | const handleSubmit = async (e) => { 18 | e.preventDefault(); 19 | 20 | try { 21 | const response = await fetch( 22 | "https://recipe-app-mern.onrender.com/auth/forgotpassword", 23 | { 24 | method: "PUT", 25 | headers: { 26 | "Content-Type": "application/json", 27 | }, 28 | body: JSON.stringify(formData), 29 | } 30 | ); 31 | 32 | if (response.ok) { 33 | const data = await response.json(); 34 | setMessage(data.message); 35 | toast.success("Password Updated successfully"); 36 | 37 | setTimeout(() => { 38 | window.location.href = "/login"; 39 | }, 4000); 40 | } else { 41 | setMessage("An error occurred while updating the password."); 42 | toast.error("Error in Password update"); 43 | } 44 | } catch (error) { 45 | console.error(error); 46 | setMessage("An error occurred while updating the password."); 47 | } 48 | }; 49 | 50 | return ( 51 |
52 |

Update Password

53 |
54 |
55 | 56 | 63 |
64 |
65 | 66 | 73 |
74 | 75 |
76 | {message &&

{message}

} 77 | 78 |
79 | ); 80 | }; 81 | 82 | export default UpdatePassword; 83 | -------------------------------------------------------------------------------- /client/my-app/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /client/my-app/src/components/Navbar.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import { NavLink } from "react-router-dom"; 3 | import "../App.css"; 4 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; 5 | import { faBars, faRotate } from "@fortawesome/free-solid-svg-icons"; 6 | 7 | const Navbar = () => { 8 | const [isOpen, setIsOpen] = useState(false); 9 | 10 | const LogoutUser = () => { 11 | if (window.confirm("You wanna logout?")) { 12 | localStorage.clear(); 13 | window.location.href = "/login"; 14 | } else { 15 | window.location.href = "/recipes"; 16 | } 17 | }; 18 | 19 | const toggleMenu = () => { 20 | setIsOpen(!isOpen); 21 | }; 22 | 23 | const auth = localStorage.getItem("token"); 24 | 25 | const handleToggleMenu = () => { 26 | setIsOpen(false); 27 | }; 28 | 29 | return ( 30 |
31 | 84 |
85 | ); 86 | }; 87 | 88 | export default Navbar; 89 | -------------------------------------------------------------------------------- /client/my-app/src/components/Register.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import "../App.css"; 3 | import { ToastContainer, toast } from "react-toastify"; 4 | import "react-toastify/dist/ReactToastify.css"; // Import the CSS for styling 5 | 6 | const Register = () => { 7 | const [name, setName] = useState(""); 8 | const [email, setEmail] = useState(""); 9 | const [password, setPassword] = useState(""); 10 | const [showError, setShowError] = useState(false); // State to control the error message visibility 11 | const Email = email.toLowerCase(); 12 | const handleSubmit = async (e) => { 13 | e.preventDefault(); 14 | 15 | if (!email || !password || !name) { 16 | // If any of the fields are empty, show the error message 17 | setShowError(true); 18 | return; // Prevent further execution 19 | } 20 | 21 | try { 22 | const response = await fetch( 23 | "https://recipe-app-mern.onrender.com/auth/register", 24 | { 25 | method: "POST", 26 | headers: { "Content-Type": "application/json" }, 27 | body: JSON.stringify({ name, email: Email, password }), 28 | } 29 | ); 30 | 31 | if (response.ok) { 32 | const user = await response.json(); 33 | 34 | if (user.error) { 35 | toast.warn("User already exists. Try with different email"); 36 | } else { 37 | toast.success("Registration successful."); 38 | localStorage.setItem("token", user.token); 39 | setTimeout(() => { 40 | window.location.href = "/"; 41 | }, 4000); 42 | } 43 | } else { 44 | console.error("Failed to register user:", response.status); 45 | } 46 | } catch (error) { 47 | toast.error("An error occurred while registering user:", error); 48 | } 49 | }; 50 | 51 | return ( 52 |
53 |
handleSubmit(e)}> 54 |

SignUp

55 | setName(e.target.value)} 59 | /> 60 | setEmail(e.target.value)} 64 | /> 65 | setPassword(e.target.value)} 69 | /> 70 | 71 |
72 | {showError && ( 73 | Please Fill all the fields 74 | )} 75 | 76 |
77 | ); 78 | }; 79 | 80 | export default Register; 81 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Recipe Sharing Full Stack App (MERN Stack) 2 | 3 | ## Table of Contents 4 | 5 | - [Screenshots](#screenshots) 6 | - [Features](#features) 7 | - [Prerequisites](#prerequisites) 8 | - [Getting Started](#getting-started) 9 | - [Folder Structure](#folder-structure) 10 | - [Technologies Used](#technologies-used) 11 | - [Live Demo](#live-demo) 12 | 13 | - ## Screenshots 14 | 15 | ![Screenshot1](./public/static/images/website1.png); 16 | ![Screenshot2](./public/static/images/website2.png); 17 | ![Screenshot3](./public/static/images/website3.png); 18 | ![Screenshot4](./public/static/images/website4.png); 19 | 20 | ## Features 21 | 22 | 1. **User Authentication**: Secure user authentication and registration system. 23 | 2. **Recipe Management**: Create, edit, and delete your recipes. 24 | 3. **Recipe Discovery**: Browse and search for recipes shared by other users. 25 | 4. **Comments and Ratings**: Leave comments and rate recipes. 26 | 5. **Favorite Recipes**: Save your favorite recipes for easy access. 27 | 6. **Responsive Design**: Works seamlessly on both desktop and mobile devices. 28 | 29 | ## Prerequisites 30 | 31 | - [Node.js](https://nodejs.org/) installed (v14 or higher). 32 | - [MongoDB](https://www.mongodb.com/) installed and running locally or on a remote server. 33 | - [Git](https://git-scm.com/) for version control. 34 | - A text editor or integrated development environment (IDE) of your choice (e.g., Visual Studio Code). 35 | 36 | ## Getting Started 37 | 38 | 1. Clone the repository: 39 | 40 | ```bash 41 | git clone https://github.com/Rohith-Manjunath/MERN-Recipe-App.git 42 | 43 | 2. Navigate to the project directory: 44 | 45 | cd Mern-Recipe-App 46 | 47 | 3. Navigate to the client directory: 48 | 49 | cd client 50 | cd my-app 51 | 52 | 4. Install client dependencies: 53 | 54 | npm install 55 | 56 | 5. Return to the project root: 57 | 58 | cd .. 59 | cd .. 60 | 61 | 6. Navigate to server folder: 62 | 63 | cd server 64 | 65 | 7. Create a `.env` file in the project root and configure your environment variables: 66 | 67 | PORT=2000 68 | MONGODB_URI=mongodb://localhost/recipe-app 69 | SECRET=your-secret-key 70 | 71 | Replace `your-secret-key` with a secure secret for JWT token generation. 72 | 73 | 8. Start the development server 74 | 75 | node index.js 76 | 77 | 78 | ## Folder Structure 79 | The project follows a standard MERN stack folder structure: 80 | 81 | - client: Contains the React frontend application. 82 | - server: Contains the Express.js backend application. 83 | - Schema: Define the MongoDB schemas and models. 84 | - routes: Define the API routes. 85 | - controllers: Handle route logic and interact with the database. 86 | - middlewares: Custom middleware functions. 87 | - db: Configuration files (e.g., database connection). 88 | 89 | ## Technologies Used 90 | #### Frontend: 91 | 92 | - React 93 | 94 | #### Backend: 95 | 96 | - Node.js 97 | - Express.js 98 | - MongoDB (Mongoose) 99 | - JSON Web Tokens (JWT) for authentication 100 | - bcrypt for secured password hashing 101 | 102 | 103 | ## Live Demo 104 | 105 | Check out the live demo of the Recipe Sharing Full Stack App [here](https://benevolent-donut-65e579.netlify.app). 106 | 107 | -------------------------------------------------------------------------------- /client/my-app/src/styles/RecipeStyle.css: -------------------------------------------------------------------------------- 1 | /* Base styles for Recipes component */ 2 | .Recipes { 3 | display: flex; 4 | flex-wrap: wrap; 5 | gap: 20px; 6 | margin: 20px; 7 | margin-top: 7rem; 8 | } 9 | 10 | /* Style for each individual recipe card */ 11 | .Recipe { 12 | background-color: #f8f8f8; 13 | border: 1px solid #ddd; 14 | padding: 20px; 15 | border-radius: 5px; 16 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); 17 | width: calc(33.33% - 20px); /* Three columns with 20px gap */ 18 | } 19 | 20 | /* Style for recipe title */ 21 | .Recipe h2 { 22 | font-size: 20px; 23 | margin-top: 0; 24 | margin-bottom: 10px; 25 | } 26 | 27 | /* Style for recipe image */ 28 | .Recipe img { 29 | max-width: 100%; 30 | height: auto; 31 | border-radius: 5px; 32 | } 33 | 34 | /* Style for ingredients list */ 35 | .Recipe h3 { 36 | font-size: 16px; 37 | margin: 10px 0; 38 | } 39 | 40 | .Recipe ul { 41 | list-style-type: disc; 42 | margin-left: 20px; 43 | padding-left: 10px; 44 | } 45 | 46 | /* Style for instructions */ 47 | .Recipe p { 48 | font-size: 14px; 49 | line-height: 1.4; 50 | margin-top: 10px; 51 | } 52 | 53 | /* Styling for regular links */ 54 | .Recipe a { 55 | color: #007bff; /* Default link color */ 56 | text-decoration: none; /* Remove underlines */ 57 | transition: color 0.3s ease; /* Smooth color transition on hover */ 58 | margin-left: 1rem; 59 | } 60 | 61 | 62 | 63 | 64 | /* Style for delete button */ 65 | .delete-button { 66 | background-color: #dc3545; 67 | color: #fff; 68 | padding: 8px 15px; 69 | border: none; 70 | border-radius: 3px; 71 | font-size: 14px; 72 | cursor: pointer; 73 | transition: background-color 0.3s ease; 74 | } 75 | 76 | .delete-button:hover { 77 | background-color: #c82333; 78 | } 79 | 80 | /* RecipeStyle.css */ 81 | 82 | /* Existing styles for other elements... */ 83 | 84 | .add-to-favorites-button { 85 | background-color: #007bff; /* Blue color, you can change this to your preferred color */ 86 | color: #fff; /* Text color */ 87 | border: none; 88 | padding: 5px 10px; 89 | margin-top: 10px; 90 | margin-left: 5px; 91 | border-radius: 5px; 92 | cursor: pointer; 93 | font-size: 16px; 94 | } 95 | 96 | .add-to-favorites-button:hover { 97 | background-color: #0056b3; /* Darker blue color on hover */ 98 | } 99 | 100 | .no-recipes{ 101 | margin-top: 5rem; 102 | } 103 | 104 | /* Adjust the styles as needed to match your design preferences */ 105 | 106 | 107 | /* Responsive Styles */ 108 | 109 | /* For devices with a screen width between 320px and 480px */ 110 | @media (min-width: 320px) and (max-width: 768px) { 111 | .Recipes { 112 | gap: 10px; /* Adjust the gap as needed for smaller screens */ 113 | } 114 | 115 | .Recipe { 116 | width: 100%; /* Make recipe cards occupy full width */ 117 | } 118 | } 119 | 120 | 121 | 122 | 123 | /* For laptops and larger screens */ 124 | @media (min-width: 992px) { 125 | .Recipes { 126 | gap: 40px; 127 | } 128 | 129 | .Recipe { 130 | width: calc(33.33% - 40px); /* Three columns with 40px gap */ 131 | } 132 | } 133 | 134 | /* For larger screens (adjust as needed) */ 135 | @media (min-width: 1200px) { 136 | .Recipes { 137 | gap: 50px; 138 | } 139 | 140 | .Recipe { 141 | width: calc(30% - 50px); /* Four columns with 50px gap */ 142 | } 143 | } 144 | 145 | 146 | -------------------------------------------------------------------------------- /client/my-app/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /client/my-app/src/components/likedProducts.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import "../styles/likedProducts.css"; 3 | import { toast, ToastContainer } from "react-toastify"; 4 | 5 | const LikedProducts = () => { 6 | const [likedProducts, setLikedProducts] = useState([]); 7 | 8 | useEffect(() => { 9 | // Call the async function to fetch liked products when the component mounts 10 | fetchLikedProducts(); 11 | }, []); 12 | 13 | const fetchLikedProducts = async () => { 14 | try { 15 | // Make a GET request to the /api/liked-products endpoint 16 | const response = await fetch( 17 | "https://recipe-app-mern.onrender.com/auth/likedRecipes" 18 | ); 19 | 20 | if (!response.ok) { 21 | toast.error("Failed to fetch liked products"); 22 | } 23 | 24 | const data = await response.json(); 25 | 26 | // Set the fetched data to the state 27 | setLikedProducts(data); 28 | } catch (error) { 29 | toast.error("Error fetching liked products:", error); 30 | } 31 | }; 32 | 33 | const handleRemoveItem = async (recipeId) => { 34 | try { 35 | if ( 36 | window.confirm( 37 | "Are you sure you wanna remove this recipe from favourites??" 38 | ) 39 | ) { 40 | const response = await fetch( 41 | `https://recipe-app-mern.onrender.com/auth/removeLiked/${recipeId}`, 42 | { 43 | method: "DELETE", 44 | } 45 | ); 46 | 47 | if (response.ok) { 48 | toast.success("Item Removed successfully"); 49 | fetchLikedProducts(); 50 | setTimeout(() => { 51 | window.location.href = "/favouriteRecipes"; 52 | }, 4000); 53 | } else { 54 | const data = await response.json(); 55 | toast.error(data.error); 56 | } 57 | } else { 58 | window.location.href = "/favouriteRecipes"; 59 | } 60 | } catch (error) { 61 | toast.error("Error removing item from liked products:", error); 62 | } 63 | }; 64 | 65 | return ( 66 |
67 |

Favourites

68 |
    69 | {likedProducts.map((product) => ( 70 |
  • 71 |
    72 |

    {product.title}

    73 |

    {product.description}

    74 | {product.title} 75 |

    Ingredients:

    76 |
      77 | {product.ingredients.length > 0 && ( 78 |
        79 | {product.ingredients.map((ingredient, index) => ( 80 |
      • {ingredient}
      • 81 | ))} 82 |
      83 | )} 84 |
    85 | 86 |
    87 |

    Instructions:

    88 |
    89 | {product.instructions.split("\n").map((step, index) => ( 90 |

    {step}

    91 | ))} 92 |
    93 |
    94 | 95 | 101 |
    102 |
  • 103 | ))} 104 |
105 | 106 |
107 | ); 108 | }; 109 | 110 | export default LikedProducts; 111 | -------------------------------------------------------------------------------- /client/my-app/src/components/AddRecipe.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import "../styles/Addrecipe.css"; 3 | import { ToastContainer, toast } from "react-toastify"; 4 | import "react-toastify/dist/ReactToastify.css"; // Import the CSS for styling 5 | 6 | const AddRecipe = () => { 7 | const [recipe, setRecipe] = useState({ 8 | title: "", 9 | ingredients: [""], 10 | instructions: "", 11 | imageUrl: "", 12 | }); 13 | 14 | const handleInputChange = (e) => { 15 | const { name, value } = e.target; 16 | setRecipe({ 17 | ...recipe, 18 | [name]: value, 19 | }); 20 | }; 21 | 22 | const handleAddIngredient = () => { 23 | const lastIngredient = recipe.ingredients[recipe.ingredients.length - 1]; 24 | if (lastIngredient !== "") { 25 | setRecipe({ 26 | ...recipe, 27 | ingredients: [...recipe.ingredients, ""], 28 | }); 29 | } 30 | }; 31 | 32 | const handleIngredientChange = (index, value) => { 33 | const updatedIngredients = [...recipe.ingredients]; 34 | updatedIngredients[index] = value; 35 | setRecipe({ 36 | ...recipe, 37 | ingredients: updatedIngredients, 38 | }); 39 | }; 40 | 41 | const handleSubmit = async (e) => { 42 | e.preventDefault(); 43 | // Send a POST request to add the recipe to the server 44 | 45 | const nonEmptyIngredients = recipe.ingredients.filter( 46 | (ingredient) => ingredient.trim() !== "" 47 | ); 48 | 49 | if (nonEmptyIngredients.length === 0) { 50 | toast.warn("Please provide at least one non-empty ingredient."); 51 | return; 52 | } 53 | 54 | try { 55 | const response = await fetch( 56 | "https://recipe-app-mern.onrender.com/auth/recipe", 57 | { 58 | method: "POST", 59 | headers: { 60 | "Content-Type": "application/json", 61 | }, 62 | body: JSON.stringify(recipe), 63 | } 64 | ); 65 | 66 | if (response.ok) { 67 | // Recipe added successfully, you can show a success message or redirect to another page 68 | toast.success("Recipe added successfully"); 69 | 70 | setTimeout(() => { 71 | window.location.href = "/recipes"; 72 | }, 4000); 73 | } else { 74 | toast.error("Failed to add recipe:", response.status); 75 | } 76 | } catch (error) { 77 | toast.error("An error occurred while adding the recipe:", error); 78 | } 79 | }; 80 | 81 | return ( 82 |
83 |

Add Recipe

84 |
85 |
86 | 87 | 93 |
94 |
95 | 96 | {recipe.ingredients.map((ingredient, index) => ( 97 | handleIngredientChange(index, e.target.value)} 102 | /> 103 | ))} 104 | 107 |
108 |
109 | 110 |