diff --git a/api-lib/db/post.js b/api-lib/db/post.js index 0a409cb..6e0dd29 100644 --- a/api-lib/db/post.js +++ b/api-lib/db/post.js @@ -4,11 +4,9 @@ import { dbProjectionUsers } from './user'; export async function findPostById(db, id) { const post = await db.collection('posts').findOne({ _id: id }); if (!post) return null; - if (withUser) { - post.creator = await db - .collection('users') - .findOne({ _id: post.creatorId }, { projection: dbProjectionUsers() }); - } + post.creator = await db + .collection('users') + .findOne({ _id: post.creatorId }, { projection: dbProjectionUsers() }); return post; } diff --git a/pages/user/[username]/post/[postId].jsx b/pages/user/[username]/post/[postId].jsx index 0f4f3fe..f8e6519 100644 --- a/pages/user/[username]/post/[postId].jsx +++ b/pages/user/[username]/post/[postId].jsx @@ -25,7 +25,7 @@ export default function UserPost({ post }) { export async function getServerSideProps(context) { await nc().use(database).run(context.req, context.res); - const post = await findPostById(context.req.db, context.params.postId); + const post = await findPostById(context.req.db, context.params.postId, true); if (!post) { return { notFound: true,