diff --git a/packages/api/src/routes/comments.ts b/packages/api/src/routes/comments.ts index aef01f9..4814386 100644 --- a/packages/api/src/routes/comments.ts +++ b/packages/api/src/routes/comments.ts @@ -157,11 +157,19 @@ export default async function commentRoutes(app: FastifyInstance) { const cleanBody = body.body.replace(INVISIBLE_RE, ''); const isAdmin = !!req.adminId; + + // use admin's linked user as author when commenting as admin + let commentAuthorId = req.user!.id; + if (isAdmin) { + const adminUser = await prisma.adminUser.findUnique({ where: { id: req.adminId! }, select: { linkedUserId: true } }); + if (adminUser?.linkedUserId) commentAuthorId = adminUser.linkedUserId; + } + const comment = await prisma.comment.create({ data: { body: cleanBody, postId: post.id, - authorId: req.user!.id, + authorId: commentAuthorId, replyToId: body.replyToId ?? null, isAdmin, adminUserId: req.adminId ?? null,