Skip to content

Commit 2dd19f4

Browse files
committed
Fix: Modified api end points
1 parent e7209b3 commit 2dd19f4

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Diff for: app.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ const verifyToken = (req, res, next) => {
5656
};
5757

5858

59-
// Set up multer storage
60-
const storage = multer.diskStorage({
61-
destination: function (req, file, cb) {
62-
cb(null, 'uploads/')
63-
},
64-
filename: function (req, file, cb) {
65-
cb(null, file.originalname)
66-
}
67-
});
68-
6959
// const upload = multer({ storage: storage });
7060

7161
// user signup route
@@ -206,9 +196,12 @@ app.post('/api/blogs', verifyToken, async (req, res) => {
206196

207197

208198
// Get all blog posts
209-
app.get('/api/blogs', async (req, res) => {
199+
app.get('/api/blogs', verifyToken, async (req, res) => {
210200
try {
211-
const blogs = await Blog.find().populate('author', 'fullName email');
201+
const userId = req.userId; // Extract userId from token
202+
203+
const blogs = await Blog.find({ author: userId }).populate('author', 'fullName email');
204+
212205
res.status(200).json(blogs);
213206
} catch (error) {
214207
console.error('Error fetching blogs:', error);

0 commit comments

Comments
 (0)