Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backend/controllers/forum.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ async function listForums(req, res, next) {
res.json(forums);
} catch (err) { next(err); }
}
// add new forum topic
// add new forum topic - author is always the authenticated caller (#263)
async function addForum(req, res, next) {
try {
const topicData = {
title: req.body.title,
description: req.body.description,
user: req.body.user_id || req.body.user
// Always derive the author from the verified JWT payload.
// Trusting req.body.user_id or req.body.user allows any
// authenticated caller to impersonate another user.
user: req.user.id || req.user._id,
};
const topic = await ForumTopic.create(topicData);
res.status(201).json(topic);
Expand Down
Loading