Skip to content

Commit

Permalink
router seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
aahmadyar123 committed Aug 26, 2023
1 parent bdebc17 commit af3c205
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
10 changes: 5 additions & 5 deletions backend/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const dotenv = require("dotenv");
dotenv.config();

//import routes
const authRoutes = require("./routes/authRoutes")
const userRoutes = require("./routes/authRoutes")
const ingredientRoutes = require("./routes/authRoutes")
const recipeRoutes = require("./routes/authRoutes")
const authRoutes = require("./routes/authRoutes");
const userRoutes = require("./routes/userRoutes");
const ingredientRoutes = require("./routes/ingredientRoutes");
const recipeRoutes = require("./routes/recipeRoutes");

// Spoonacular API methods
const recipeAPI = require("./recipeAPI.js");
Expand Down Expand Up @@ -54,7 +54,7 @@ const port = 8000;

app.use(cors());
app.use(express.json());
//app.use(cookieParser());
app.use(cookieParser());

// auth middleware for protected routes
app.use("/recipes", authenticateToken);
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const router = express.Router();
//DB models
const userServices = require("../controllers/user-services");

const jwt = require("jsonwebtoken");

function generateAccessToken(id) {
/*
Expand All @@ -23,7 +24,6 @@ function generateAccessToken(id) {
// the database
router.post("/login", async (req, res) => {
const user = req.body;
console.log(user);
try {
const result = await userServices.login(user.email, user.password);

Expand Down
2 changes: 1 addition & 1 deletion backend/routes/ingredientRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ router.put("/", async (req, res) => {
});


modules.exports = router;
module.exports = router;
2 changes: 2 additions & 0 deletions backend/routes/recipeRoutes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const express = require("express");
const router = express.Router();

router.use(express.json())

//DB models
const userServices = require("../controllers/user-services");
const recipeServices = require("../controllers/recipe-services");
Expand Down
3 changes: 3 additions & 0 deletions backend/routes/userRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const router = express.Router();

//DB models
const userServices = require("../controllers/user-services");
const { model } = require("mongoose");


// --------------------------------------------------
Expand Down Expand Up @@ -75,3 +76,5 @@ router.post("/:id/recipes", async (req, res) => {
res.status(500).send("Internal Server Error.");
}
});

module.exports = router;
4 changes: 2 additions & 2 deletions react-frontend/src/components/context/AuthProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const AuthProvider = ({ children }) => {
const navigate = useNavigate();

const handleRegister = async (user) => {
const response = await axios.post(process.env.REACT_APP_BACKEND_URL, user);
const response = await axios.post(`${process.env.REACT_APP_BACKEND_URL}/register`, user);
const token = response.data['token']
setToken(token);

Expand Down Expand Up @@ -47,7 +47,7 @@ export const AuthProvider = ({ children }) => {
console.log("In Login");

try{
const response = await axios.post(process.env.REACT_APP_BACKEND_URL, user);
const response = await axios.post(`${process.env.REACT_APP_BACKEND_URL}/login`, user);
if (response.status === 201){
const token = response.data['token'];
setToken(token);
Expand Down

0 comments on commit af3c205

Please sign in to comment.