Skip to content

Commit

Permalink
pulled from render-home.
Browse files Browse the repository at this point in the history
  • Loading branch information
manushreesaboo committed Nov 9, 2023
2 parents a0d1792 + 9005127 commit e937cc0
Show file tree
Hide file tree
Showing 16 changed files with 15,792 additions and 95 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,11 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
<<<<<<< HEAD

.idea/
<<<<<<< HEAD
=======
=======
>>>>>>> 21663079c1a9fede0572553c329c00b252add687
>>>>>>> 9005127b42abcc77431f4c1a61a0ed43b4ec9999
12 changes: 12 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ const express = require("express");
const connectDB = require("./db");
const userRoutes = require("./routes/user");
const itemRoutes = require("./routes/item");
<<<<<<< HEAD
var cors = require("cors");
=======
const cors = require("cors");
>>>>>>> 9005127b42abcc77431f4c1a61a0ed43b4ec9999

const app = express();
const PORT = process.env.PORT || 3000;

app.use(
cors({
origin: "http://localhost:3001",
credentials: true, // Allow credentials (cookies, authorization headers)
exposedHeaders: ["Authorization"], // Expose additional headers if needed
})
);

// Connect to MongoDB
connectDB();

Expand Down
82 changes: 50 additions & 32 deletions backend/routes/user.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
const express = require('express');
const { authenticate, checkRequiredAttributes } = require('../middlewares/user');
const UserController = require('../controllers/user')
const express = require("express");
const {
authenticate,
checkRequiredAttributes,
} = require("../middlewares/user");
const UserController = require("../controllers/user");

const router = express.Router();

router.route('/testLogin')
.get(authenticate, (req, res) => {
res.json({ message: `Welcome ${req.user.email}` });
});
router.route("/testLogin").get(authenticate, (req, res) => {
res.json({ message: `Welcome ${req.user.email}` });
});

router.route('/register')
.post(checkRequiredAttributes(["email", "OTP", "password", "firstName", "lastName"]),
router
.route("/register")
.post(
checkRequiredAttributes([
"email",
"OTP",
"password",
"firstName",
"lastName",
]),
async (req, res) => {
try {
await UserController.register(req, res, errorHandler);
} catch (err) {
res.json({ message: `Register User Error: ${err}` })
res.json({ message: `Register User Error: ${err}` });
}
})
}
);

router.route('/login')
.post(checkRequiredAttributes(["email", "password"]),
async (req, res) => {
try {
await UserController.login(req, res, errorHandler);
} catch (err) {
res.json({ message: `Login User Error: ${err}` })
}
})
router
.route("/login")
.post(checkRequiredAttributes(["email", "password"]), async (req, res) => {
try {
await UserController.login(req, res, errorHandler);
} catch (err) {
res.json({ message: `Login User Error: ${err}` });
}
});

router.route('/sendOTP')
.post(checkRequiredAttributes(["email"]),
async (req, res) => {
try {
await UserController.sendOTP(req, res, errorHandler);
} catch (err) {
res.json({ message: `Failed to send OTP: ${err}` })
}
})
router
.route("/sendOTP")
.post(checkRequiredAttributes(["email"]), async (req, res) => {
try {
await UserController.sendOTP(req, res, errorHandler);
} catch (err) {
res.json({ message: `Failed to send OTP: ${err}` });
}
});

<<<<<<< HEAD
router.route('/edit')
.post(authenticate,
checkRequiredAttributes(["email"]),
async (req, res) => {
=======
router
.route("/edit")
// TODO: add checkRequiredAttributes middleware
.post(authenticate, checkRequiredAttributes(["email"]), async (req, res) => {
>>>>>>> 9005127b42abcc77431f4c1a61a0ed43b4ec9999
try {
await UserController.edit(req, res, errorHandler);
} catch (err) {
res.json({ message: `Edit User Error: ${err}` })
res.json({ message: `Edit User Error: ${err}` });
}
})
});

const errorHandler = (err) => {}
const errorHandler = (err) => {};

module.exports = router;
Loading

0 comments on commit e937cc0

Please sign in to comment.