From 68f5ca6bed0e57cec1956974da9da88da1f6a8ac Mon Sep 17 00:00:00 2001 From: TimTimich6 Date: Tue, 23 Jan 2024 14:39:41 -0800 Subject: [PATCH] fix: takes passport's user name instead of the one passed in frontend --- api/src/controllers/reviews.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/controllers/reviews.ts b/api/src/controllers/reviews.ts index 6fa04f00..108bdbea 100644 --- a/api/src/controllers/reviews.ts +++ b/api/src/controllers/reviews.ts @@ -134,7 +134,6 @@ router.get('/', async function (req, res, next) { router.post('/', async function (req, res, next) { if (req.session.passport) { //^ this should be a middleware check smh - console.log('Adding Review:', req.body); // check if user is trusted const reviewsCollection = await getCollection(COLLECTION_NAMES.REVIEWS); @@ -165,6 +164,9 @@ router.post('/', async function (req, res, next) { if (reviews?.length > 0) return res.status(400).json({ error: 'Review already exists for this professor and course!' }); // add review to mongo + req.body.userDisplay = + req.body.userDisplay === 'Anonymous Peter' ? 'Anonymous Peter' : req.session.passport.user.name; + req.body.userID = req.session.passport.user.id; await addDocument(COLLECTION_NAMES.REVIEWS, req.body); // echo back body