Adds collaborative comments to the collections and globals you list, shown in a document side panel, a global drawer and badges on field labels. Comments are stored in plugin-owned collections and served through the plugin's own endpoints, with permissions granted through an access policy. Requires Payload 3.90 or later, the companion guard plugin and a config wrapped in its access policy helper.
Installation
npm i @focus-reactive/payload-plugin-comments37
Stars
5
Forks
33
Open Issues
Today
Last Updated
5.5k
Weekly Downloads
v2.0.1
npm Version
686.0 KB
Unpacked Size
8
Dependencies
37+22 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 37 |
| Dec 4, 2026 | 37 |
| Dec 3, 2026 | 37 |
| Dec 2, 2026 | 37 |
| Dec 1, 2026 | 36 |
| Nov 30, 2026 | 35 |
| Nov 29, 2026 | 35 |
| Nov 28, 2026 | 34 |
| Nov 27, 2026 | 34 |
| Nov 26, 2026 | 34 |
| Nov 25, 2026 | 34 |
| Nov 24, 2026 | 34 |
| Nov 23, 2026 | 34 |
| Nov 22, 2026 | 34 |
| Nov 21, 2026 | 34 |
| Nov 20, 2026 | 33 |
| Nov 19, 2026 | 32 |
| Nov 18, 2026 | 32 |
| Nov 17, 2026 | 32 |
| Nov 16, 2026 | 32 |
| Nov 15, 2026 | 32 |
| Nov 14, 2026 | 32 |
| Nov 13, 2026 | 32 |
| Nov 12, 2026 | 32 |
| Nov 11, 2026 | 32 |
| Nov 10, 2026 | 32 |
| Nov 9, 2026 | 31 |
| Nov 8, 2026 | 31 |
| Nov 7, 2026 | 31 |
| Nov 6, 2026 | 31 |
| Nov 5, 2026 | 31 |
| Nov 4, 2026 | 30 |
| Nov 3, 2026 | 30 |
| Nov 2, 2026 | 30 |
| Nov 1, 2026 | 30 |
| Oct 31, 2026 | 30 |
| Oct 30, 2026 | 30 |
| Oct 29, 2026 | 30 |
| Oct 28, 2026 | 30 |
| Oct 27, 2026 | 30 |
| Oct 26, 2026 | 30 |
| Oct 25, 2026 | 30 |
| Oct 24, 2026 | 29 |
| Oct 23, 2026 | 29 |
| Oct 22, 2026 | 29 |
| Oct 21, 2026 | 29 |
| Oct 20, 2026 | 29 |
| Oct 19, 2026 | 29 |
| Oct 18, 2026 | 29 |
| Oct 17, 2026 | 27 |
| Oct 16, 2026 | 26 |
| Oct 15, 2026 | 26 |
| Oct 14, 2026 | 26 |
| Oct 13, 2026 | 25 |
| Oct 12, 2026 | 25 |
| Oct 11, 2026 | 25 |
| Oct 10, 2026 | 25 |
| Oct 9, 2026 | 25 |
| Oct 8, 2026 | 25 |
| Oct 7, 2026 | 25 |
| Oct 6, 2026 | 24 |
| Oct 5, 2026 | 24 |
| Oct 4, 2026 | 24 |
| Oct 3, 2026 | 23 |
| Oct 2, 2026 | 22 |
| Oct 1, 2026 | 22 |
| Sep 30, 2026 | 20 |
| Sep 29, 2026 | 20 |
| Sep 28, 2026 | 20 |
| Sep 27, 2026 | 20 |
| Sep 26, 2026 | 19 |
| Sep 25, 2026 | 18 |
| Sep 24, 2026 | 18 |
| Sep 23, 2026 | 18 |
| Sep 22, 2026 | 18 |
| Sep 21, 2026 | 18 |
| Sep 20, 2026 | 18 |
| Sep 19, 2026 | 18 |
| Sep 18, 2026 | 18 |
| Sep 17, 2026 | 18 |
| Sep 16, 2026 | 18 |
| Sep 15, 2026 | 18 |
| Sep 14, 2026 | 18 |
| Sep 13, 2026 | 17 |
| Sep 12, 2026 | 17 |
| Sep 11, 2026 | 17 |
| Sep 10, 2026 | 16 |
| Sep 9, 2026 | 16 |
| Sep 8, 2026 | 16 |
| Sep 7, 2026 | 15 |
| Sep 6, 2026 | 15 |
Shared by 15 plugins in focusreactive/payload-plugins.
4.7K+4.2K since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 4,675 |
| Dec 4, 2026 | 4,085 |
| Dec 3, 2026 | 2,778 |
| Dec 2, 2026 | 2,070 |
| Dec 1, 2026 | 1,994 |
| Nov 30, 2026 | 1,947 |
| Nov 29, 2026 | 1,506 |
| Nov 28, 2026 | 4,339 |
| Nov 27, 2026 | 4,544 |
| Nov 26, 2026 | 6,739 |
| Nov 25, 2026 | 9,387 |
| Nov 24, 2026 | 9,944 |
| Nov 23, 2026 | 11,929 |
| Nov 22, 2026 | 14,021 |
| Nov 21, 2026 | 13,773 |
| Nov 20, 2026 | 13,989 |
| Nov 19, 2026 | 11,602 |
| Nov 18, 2026 | 9,194 |
| Nov 17, 2026 | 8,798 |
| Nov 16, 2026 | 6,817 |
| Nov 15, 2026 | 5,922 |
| Nov 14, 2026 | 3,770 |
| Nov 13, 2026 | 5,009 |
| Nov 12, 2026 | 8,019 |
| Nov 11, 2026 | 10,744 |
| Nov 10, 2026 | 15,006 |
| Nov 9, 2026 | 19,133 |
| Nov 8, 2026 | 20,052 |
| Nov 7, 2026 | 20,384 |
| Nov 6, 2026 | 19,858 |
| Nov 5, 2026 | 17,186 |
| Nov 4, 2026 | 14,565 |
| Nov 3, 2026 | 10,143 |
| Nov 2, 2026 | 6,292 |
| Nov 1, 2026 | 7,713 |
| Oct 31, 2026 | 7,982 |
| Oct 30, 2026 | 7,435 |
| Oct 29, 2026 | 6,546 |
| Oct 28, 2026 | 6,052 |
| Oct 27, 2026 | 8,812 |
| Oct 26, 2026 | 12,529 |
| Oct 25, 2026 | 11,827 |
| Oct 24, 2026 | 11,545 |
| Oct 23, 2026 | 10,631 |
| Oct 22, 2026 | 11,249 |
| Oct 21, 2026 | 12,159 |
| Oct 20, 2026 | 9,375 |
| Oct 19, 2026 | 5,371 |
| Oct 18, 2026 | 3,479 |
| Oct 17, 2026 | 3,007 |
| Oct 16, 2026 | 3,709 |
| Oct 15, 2026 | 3,944 |
| Oct 14, 2026 | 5,013 |
| Oct 13, 2026 | 5,310 |
| Oct 12, 2026 | 6,651 |
| Oct 11, 2026 | 6,647 |
| Oct 10, 2026 | 7,967 |
| Oct 9, 2026 | 9,172 |
| Oct 8, 2026 | 11,782 |
| Oct 7, 2026 | 11,225 |
| Oct 6, 2026 | 11,230 |
| Oct 5, 2026 | 10,444 |
| Oct 4, 2026 | 9,755 |
| Oct 3, 2026 | 8,475 |
| Oct 2, 2026 | 6,613 |
| Oct 1, 2026 | 3,228 |
| Sep 30, 2026 | 1,864 |
| Sep 29, 2026 | 1,581 |
| Sep 28, 2026 | 986 |
| Sep 27, 2026 | 973 |
| Sep 26, 2026 | 1,057 |
| Sep 25, 2026 | 3,325 |
| Sep 24, 2026 | 4,530 |
| Sep 23, 2026 | 6,976 |
| Sep 22, 2026 | 8,547 |
| Sep 21, 2026 | 9,662 |
| Sep 20, 2026 | 10,578 |
| Sep 19, 2026 | 10,433 |
| Sep 18, 2026 | 8,174 |
| Sep 17, 2026 | 7,014 |
| Sep 16, 2026 | 4,747 |
| Sep 15, 2026 | 3,315 |
| Sep 14, 2026 | 2,308 |
| Sep 13, 2026 | 1,190 |
| Sep 12, 2026 | 885 |
| Sep 11, 2026 | 987 |
| Sep 10, 2026 | 993 |
| Sep 9, 2026 | 860 |
| Sep 8, 2026 | 709 |
| Sep 7, 2026 | 604 |
| Sep 6, 2026 | 502 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1177993877-payload-plugin-comments)<a href="https://payloaddirectory.dev/plugins/1177993877-payload-plugin-comments"><img src="https://payloaddirectory.dev/badge/1177993877-payload-plugin-comments.svg" alt="Payload Directory"></a>README
A collaborative commenting plugin for Payload CMS v3. It adds document-level and field-level comments to the collections and globals you name, with @mentions, email notifications, resolution, multi-tenancy and locale-aware filtering.
The plugin is built on @focus-reactive/payload-plugin-guard.
Your project's access policy file decides who may read, write, resolve and moderate comments.
Requirements: Payload ^3.90.0, @focus-reactive/payload-plugin-guard, and a config wrapped in withAccessPolicy.
Copy and paste this prompt into your AI assistant (Cursor, Claude, etc.) to integrate the plugin into an existing Payload v3 project.
I want to add collaborative comments to my Payload CMS v3 project using
@focus-reactive/payload-plugin-comments. Follow these steps in order, and stop to ask me where a step says so.
## Rules you must follow
- Never write an access rule that admits every logged-in user: no `Boolean(req.user)`, no `() => true`,
no `({ req }) => !!req.user`. A rule names a role, or it is `nobody`.
- Do not invent roles. Ask me which roles get each capability of the plugin.
- Write every policy entry by hand in `src/access.policy.ts`, and grant each capability and each
collection right explicitly to the roles I name. Nothing is open by default.
- When the boot or a request fails, fix the cause or ask me. Never use `anyone`, a looser gate,
`overrideAccess` or a removed or disabled check to make an error go away.
- Do not add `overrideAccess: true` anywhere, and do not add `access` to the `comments` or
`comment-reads` collections: their policy entries are `nobody` for every operation.
## How it works
The plugin adds comments to the collections and globals listed in its options, and to no others.
It stores them in a `comments` collection and read markers in a `comment-reads` collection.
Only the plugin's own endpoints under `/api/comments-plugin/` read or write them; REST and GraphQL
on both collections are closed for everyone.
The server sets the author, the tenant, the resolver and the mention snapshots; a client cannot send them.
A user sees and comments on a document only when they can read that document.
It declares four capabilities that the project grants in its access policy:
- `view`: see comments, unread mention counts, and mark comments that mention them as read.
- `comment`: write comments, mention users, and delete their own comments.
- `resolve`: resolve and reopen comments.
- `moderate`: delete other users' comments.
## Step 1: install
pnpm add @focus-reactive/payload-plugin-comments @focus-reactive/payload-plugin-guard
Check that `payload` is 3.90 or later; if it is not, upgrade it first.
## Step 2: ask me about roles
Look at the auth collection named in `admin.user` and the roles it has.
Ask me, one question per capability:
"Which roles may see comments?", "Which roles may write comments?",
"Which roles may resolve comments?" and "Which roles may delete other users' comments?"
Wait for my answers. Write each answer as a gate in the policy file in step 3.
Also ask me which collections and globals should have comments, and which field is each collection's title.
## Step 3: the access policy file
Open `src/access.policy.ts`, or create it if the project has none, following the guard README
(`defineAccessPolicy`, `gate`, `filter`, `nobody`, checked with `satisfies AccessPolicy<Config>`).
If you create it, every collection and global of the config needs an entry: move each existing
`access` of the project into the file, and ask me for every rule you cannot read from the code.
Add these entries for this plugin:
collections: {
comments: { create: nobody, read: nobody, update: nobody, delete: nobody },
"comment-reads": { create: nobody, read: nobody, update: nobody, delete: nobody },
},
plugins: {
"comments-plugin": {
view: <the gate from my first answer>,
comment: <the gate from my second answer>,
resolve: <the gate from my third answer>,
moderate: <the gate from my fourth answer>,
},
},
## Step 4: register the plugin and wrap the config
// payload.config.ts
import { buildConfig } from 'payload'
import { withAccessPolicy } from '@focus-reactive/payload-plugin-guard'
import { commentsPlugin } from '@focus-reactive/payload-plugin-comments'
import { accessPolicy } from './access.policy'
export default withAccessPolicy(
accessPolicy,
buildConfig({
// ...the existing config
plugins: [
commentsPlugin({
collections: [{ slug: 'pages', titleField: 'title' }],
globals: ['settings'],
usernameFieldPath: 'name',
access: accessPolicy.plugins['comments-plugin'],
}),
],
})
)
If the project uses @payloadcms/plugin-multi-tenant, add `tenant` as in the plugin README's
"Multi-tenancy" section, with `userHasAccessToAllTenants` set to the same function the
multi-tenant plugin uses.
Run `payload generate:importmap` and `payload generate:types`.
With a SQL adapter, run `payload migrate:create` and `payload migrate`.
Start the app.
A missing or wrong policy entry stops the boot with a list of what to fix.
Fix each item; never loosen a rule to make an error go away.
## Step 5: verify, and show me the output
With the app running, send each request and show me the status code.
Every one of them must be refused. If one succeeds, the policy is wrong: stop and tell me.
1. Anonymous comment, expect 401:
curl -i -X POST http://localhost:3000/api/comments-plugin/create -H 'Content-Type: application/json' -d '{"collectionSlug":"pages","documentId":1,"text":"hi"}'
2. The same request with the session cookie of a user whose role may not write comments, expect 403.
3. Anonymous list, expect 401:
curl -i -X POST http://localhost:3000/api/comments-plugin/list -H 'Content-Type: application/json' -d '{}'
4. A direct write to the comments collection with an admin's session cookie, expect 403:
curl -i -X POST http://localhost:3000/api/comments -H 'Content-Type: application/json' -d '{"text":"hi"}'
5. A direct read of the comments collection with an admin's session cookie, expect 403:
curl -i http://localhost:3000/api/comments
6. A direct write to the read markers with an admin's session cookie, expect 403:
curl -i -X POST http://localhost:3000/api/comment-reads -H 'Content-Type: application/json' -d '{}'
Then, as a user who may write comments, open a configured document, post a comment that mentions
a colleague, and check that it appears.
A header button in the Payload admin opens a drawer listing all comments across every document and collection.
When viewing a document, a side panel shows all comments scoped to that document with filter tabs (Open / Resolved / Mentioned me).
Clicking the comment badge on a field label opens a popup where you can write and post a new comment for that specific field.
The comment button embedded in the field label has two visual states: no comments (inactive, appears on hover) and one or more open comments (active, showing the count badge).
| Inactive (no comments) | Active (has comments) |
|---|---|
@payloadcms/plugin-multi-tenant.pnpm add @focus-reactive/payload-plugin-comments @focus-reactive/payload-plugin-guard
Peer dependencies: payload ^3.90.0 and @payloadcms/ui ^3.90.0.
next, react and react-dom are optional.
The plugin reads every right from your project's access policy file; see the guard README for the whole file. Add the entries for the two collections the plugin owns, and a gate for each capability:
// src/access.policy.ts
import { defineAccessPolicy, gate, nobody } from "@focus-reactive/payload-plugin-guard";
import type { PayloadRequest } from "payload";
const rolesOf = (req: PayloadRequest): string[] =>
req.user?.collection === "users" ? (req.user.roles ?? []) : [];
const hasRole = (...roles: string[]) =>
gate(({ req }) => rolesOf(req).some((role) => roles.includes(role)));
const pluginOwned = { create: nobody, read: nobody, update: nobody, delete: nobody };
export const accessPolicy = defineAccessPolicy({
collections: {
// ...your collections
comments: pluginOwned,
"comment-reads": pluginOwned,
},
globals: {
// ...your globals
},
jobs: { run: hasRole("admin"), queue: hasRole("admin"), cancel: hasRole("admin") },
plugins: {
"comments-plugin": {
view: hasRole("admin", "editor", "reviewer"),
comment: hasRole("admin", "editor", "reviewer"),
resolve: hasRole("admin", "editor"),
moderate: hasRole("admin"),
},
},
});
Every operation of comments and comment-reads must be nobody; the boot fails otherwise.
// payload.config.ts
import { buildConfig } from "payload";
import { withAccessPolicy } from "@focus-reactive/payload-plugin-guard";
import { commentsPlugin } from "@focus-reactive/payload-plugin-comments";
import { accessPolicy } from "./access.policy";
export default withAccessPolicy(
accessPolicy,
buildConfig({
plugins: [
commentsPlugin({
collections: [
{ slug: "pages", titleField: "title" },
{ slug: "products", titleField: "name" },
],
globals: ["settings"],
usernameFieldPath: "name",
access: accessPolicy.plugins["comments-plugin"],
}),
],
})
);
access is required and has no default.
The plugin refuses to start without it, and withAccessPolicy checks that it got exactly the gates in accessPolicy.plugins["comments-plugin"].
collections is required too: only the listed collections and globals get comments.
pnpm payload generate:importmap
pnpm payload migrate:create add_comments
pnpm payload migrate
Skip the migration with the MongoDB adapter. The stylesheet loads with the plugin's admin components; there is nothing to import.
| Capability | Lets a user | Also needs |
|---|---|---|
view | see comments and unread mention counts, and mark a comment that mentions them as read | read access to the commented document |
comment | write comments, see the users they may mention, and delete their own comments | read access to the commented document |
resolve | resolve and reopen comments | read access to the commented document |
moderate | delete other users' comments | view, and read access to the commented document |
The capability says who may act at all.
The document rights come from the policy entries you already wrote for the commented collections and globals.
Every check runs on the server; the admin UI only hides what the capability lookup says the user cannot do.
A user without view sees no comment controls at all: no bell in the header, no comment icon next to a field, and no comments drawer.
A user with view but without comment sees the comments of a field but no icon to add one.
comment; anyone else needs moderate.access.admin refuses, and users without the capability get 403.warn with the capability and the caller's kind.GET /api/comments-plugin/capabilities answers a logged-in admin user with { "view": boolean, "comment": boolean, "resolve": boolean, "moderate": boolean } for that user.| Slug | Kind | Written by | Read by |
|---|---|---|---|
comments | collection | the plugin's endpoints and cascade deletes only | the plugin's endpoints only |
comment-reads | collection | the plugin's endpoints and cascade deletes only | the plugin's endpoints only |
The server sets author, tenant, isResolved, resolvedBy, resolvedAt and the mentions snapshots.
A client that sends them, in the body, a cookie or a header, has them ignored.
All endpoints are POST with a JSON body, except the capability lookup.
Path under /api/comments-plugin | Capability | Body |
|---|---|---|
/list | view | { collectionSlug, documentId }, { globalSlug }, or {} for every comment the user may see |
/unread-mentions-count | view | the same target as /list, plus locale |
/document-titles | view | { comments: [{ collectionSlug, documentId }] } |
/field-labels | view | { comments: [{ collectionSlug, documentId, globalSlug, fieldPath }] } |
/mark-read | view | { commentId } |
/delete | view, then comment for the author or moderate for anyone else | { id } |
/mentionable-users | comment | {} |
/create | comment | { collectionSlug, documentId } or { globalSlug }, plus text, fieldPath, locale |
/resolve | resolve | { id, resolved } |
GET /capabilities | a logged-in admin user | none |
text: 1 to 5000 characters, with at most 20 mentions.fieldPath: dot-separated names, at most 500 characters.locale: one of the config's locale codes.commentsPlugin({
collections: [{ slug: "pages", titleField: "title" }],
access: accessPolicy.plugins["comments-plugin"],
tenant: {
enabled: true,
collectionSlug: "tenants",
documentTenantField: "tenant",
tenantsArrayField: { arrayFieldName: "tenants", arrayTenantFieldName: "tenant" },
userHasAccessToAllTenants: (user) => user.roles?.includes("super-admin") ?? false,
},
});
tenants[].tenant by default), or every tenant when userHasAccessToAllTenants returns true.
Pass the same function you give @payloadcms/plugin-multi-tenant.Write a mention as @(<user id>) in the text; the editor inserts it from the autocomplete.
The server keeps the mentions that name a user of the admin user collection (admin.user) in the comment's tenant, drops the rest, and stores each one's display name as a snapshot.
No email address is stored in a comment or sent to the browser.
Mentioned users get one email each, through Resend, when both variables are set:
| Variable | Description | Example |
|---|---|---|
RESEND_API_KEY | Your Resend API key | re_xxxxxxxxxxxxxxxx |
RESEND_FROM_EMAIL | Sender address for mention notifications | [email protected] |
Without them, no email is sent and the server logs a warning.
The email escapes the comment text and every name.
Its link to the document is built from the config's serverURL, or NEXT_PUBLIC_SERVER_URL when serverURL is empty, and the admin route; nothing from the request goes into it.
CommentsPluginConfig| Option | Type | Default | Description |
|---|---|---|---|
access | { view, comment, resolve, moderate } | required | The gates from accessPolicy.plugins["comments-plugin"] |
collections | CollectionEntry[] | required | The collections whose documents can carry comments |
globals | string[] | [] | The globals that can carry comments |
enabled | boolean | true | false removes the endpoints and the admin UI; the collections stay |
tenant | TenantPluginConfig | none | Multi-tenancy settings |
overrides | { admin?, hooks?, fields? } | none | Additions to the comments collection |
translations | Record<string, Partial<CommentsTranslations>> | none | UI strings per locale |
usernameFieldPath | string | "name" | Dot path to the display name on the admin user collection |
CollectionEntryinterface CollectionEntry {
slug: string;
titleField?: string;
}
titleField names the field shown as the document's title in the panel.
Only that field is read, with the requesting user's access; documents without a titleField, or that the user cannot read, show their id.
usernameFieldPathThe field on the admin user collection used as the display name in comments and the mention autocomplete.
It supports dot paths such as profile.displayName.
It is the only user field the endpoints return; the email is never used as a name.
TenantPluginConfig| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | false | Turn tenant scoping on |
collectionSlug | string | "tenants" | Slug of the tenants collection |
documentTenantField | string | "tenant" | Field on commented collections that holds the document's tenant |
tenantsArrayField | { arrayFieldName?, arrayTenantFieldName? } | { "tenants", "tenant" } | Where the user record lists the user's tenants |
userHasAccessToAllTenants | (user) => boolean | always false | Users for whom it returns true act in every tenant |
overridescommentsPlugin({
// ...
overrides: {
admin: { group: "Review" },
fields: [{ name: "priority", type: "select", options: ["low", "high"] }],
hooks: { afterChange: [notifySlack] },
},
});
admin is merged into the plugin's settings, fields are appended, and hooks run after the plugin's own.
When a commented document is deleted, its comments and their read markers are removed in batches through the database adapter, so the beforeDelete and afterDelete hooks of overrides.hooks do not run for them; they run when a comment is deleted through the plugin's endpoint.
Access cannot be overridden: it comes only from the access policy.
Use translations to override any UI string for one or more locales.
Each key is a locale code; the value is a partial object of the CommentsTranslations shape.
Keys you omit fall back to the built-in English defaults.
commentsPlugin({
translations: {
fr: {
label: "Commentaires",
add: "Ajouter un commentaire",
writeComment: "Écrire un commentaire",
comment: "Commenter",
cancel: "Annuler",
resolve: "Résoudre",
reopen: "Rouvrir",
delete: "Supprimer",
filterOpen: "Ouverts",
filterResolved: "Résolus",
filterMentioned: "Me mentionnent",
},
},
});
All translatable keys (with their English defaults):
| Key | Default (English) |
|---|---|
label | "Comments" |
openComments_one | "{{count}} open comment" |
openComments_other | "{{count}} open comments" |
add | "Add comment" |
writeComment | "Write a comment" |
comment | "Comment" |
cancel | "Cancel" |
posting | "Posting…" |
resolve | "Resolve" |
reopen | "Reopen" |
delete | "Delete" |
general | "General" |
close | "Close" |
syncingComments | "Syncing comments" |
openCommentsAria | "Open comments" |
failedToPost | "Failed to post comment" |
failedToUpdate | "Failed to update comment" |
failedToDelete | "Failed to delete comment" |
failedToAdd | "Failed to add comment" |
unknownAuthor | "Unknown" |
deletedUser | "Deleted user" |
noOpenComments | "No open comments" |
noResolvedComments | "No resolved comments" |
noMentionedComments | "No comments mentioning you" |
filterOpen | "Open" |
filterResolved | "Resolved" |
filterMentioned | "Mentioned me" |
noMentionMatches | "No matches" |
The CommentsTranslations type is exported from the package so you can type your translation objects:
import type { CommentsTranslations } from "@focus-reactive/payload-plugin-comments";
const myTranslations: Record<string, Partial<CommentsTranslations>> = {
fr: { label: "Commentaires" },
de: { label: "Kommentare" },
};
commentsPlugin({ translations: myTranslations });
2.0 moves the plugin onto @focus-reactive/payload-plugin-guard; Upgrading to the guard explains the model all the plugins share, with a complete example.
Every access rule is now written by hand in your project's src/access.policy.ts, and nothing is open by default: an entry you leave out stops the boot, and a capability you do not grant is refused for everyone.
@payloadcms/* package 3.90 or later, with the React and Next versions Payload 3.90 requires, Node 22.22 or later, and @focus-reactive/payload-plugin-guard installed next to the plugin.access is a required option with four capabilities and no default.collections is required, and only the listed collections get comments; list the globals that should have comments in globals.
In 1.x every collection and global had comments.comments and comment-reads are closed for everyone; code that read or wrote comments through /api/comments uses the plugin's endpoints under /api/comments-plugin/ instead, whose paths are unchanged.overrides.access is gone, overrides.fields is an array of fields to append instead of a function, and overrides.hooks run after the plugin's hooks instead of replacing them.enabled: false turns off the endpoints and the admin UI but keeps the two collections, so their policy entries stay.moderate.overrides.hooks do not run for them.userHasAccessToAllTenants; existing comments keep their stored tenant.admin.user instead of users, and no email address is stored or returned.@payloadcms/plugin-multi-tenant is no longer a peer dependency.Upgrade payload and every @payloadcms/* package to 3.90 or later, run the server on Node 22.22 or later, and install the guard:
pnpm add @focus-reactive/payload-plugin-guard @focus-reactive/payload-plugin-comments.
Add the plugin's entries to src/access.policy.ts, with gates for your own roles; if the project has no policy file yet, write it first as the guide describes.
// src/access.policy.ts, inside defineAccessPolicy({ ... })
collections: {
comments: { create: nobody, read: nobody, update: nobody, delete: nobody },
"comment-reads": { create: nobody, read: nobody, update: nobody, delete: nobody },
},
plugins: {
"comments-plugin": {
view: isReviewer,
comment: isReviewer,
resolve: isEditor,
moderate: isAdmin,
},
},
view: see comments and unread mention counts, and mark a comment that mentions the user as read.comment: write comments, see the users they may mention, and delete their own comments.resolve: resolve and reopen comments.moderate: delete other users' comments; it needs view as well.comments and comment-reads are written and read only through the plugin, so every operation stays nobody.Pass access: accessPolicy.plugins["comments-plugin"] to commentsPlugin, and export the config wrapped: export default withAccessPolicy(accessPolicy, buildConfig({ ... })).
Database: no migration; the two collections keep their columns.
Re-test: an anonymous POST /api/comments-plugin/list answers 401, a user of another auth collection 403, and GET /api/comments as an admin 403; a user without moderate cannot delete another user's comment; then write, mention, resolve and delete a comment as the roles you granted.
plugin.ts creates the plugin with createGuardedPlugin, adds the comments and comment-reads collections with every operation locked, and registers the endpoints under /api/comments-plugin/.afterDelete cascade to each configured collection, the field-label component to each configured global, and a beforeDelete cascade for read markers to the admin user collection.CommentsProviderWrapper, CommentsHeaderButton) fetches through the endpoints with TanStack Query and updates its cache optimistically.Comments collection schema:
| Field | Type | Description |
|---|---|---|
documentId | number | ID of the commented document (null for globals) |
collectionSlug | text | Slug of the collection (null for globals) |
globalSlug | text | Slug of the global (null for collection documents) |
fieldPath | text | Dot path of the field (null for document-level comments) |
locale | text | Locale of the comment (null shows in every locale) |
text | textarea | Comment body, with @(userId) mention tokens |
mentions | array | Mentioned users with their display-name snapshots |
author | relationship | The author, set by the server |
isResolved | checkbox | Whether the comment is resolved |
resolvedBy | relationship | Who resolved it, set by the server |
resolvedAt | date | When it was resolved, set by the server |
tenant | relationship | The commented document's tenant, when multi-tenancy is on |
| Import path | Exports |
|---|---|
@focus-reactive/payload-plugin-comments | commentsPlugin, CommentsPluginConfig (type), CommentsTranslations (type) |
| Command | Description |
|---|---|
pnpm build | Build the plugin to dist/ |
pnpm dev | Build in watch mode |
pnpm lint | Lint and check formatting (Ultracite) |
pnpm lint:fix | Lint and fix, including formatting |
pnpm test | Unit tests and integration tests on a temporary SQLite database |
MIT © Focus Reactive
Topics
Tags
payload plugin netlify deploy
Deploy button in the Payload admin that builds a Netlify site, streams the log, and publishes a preview
72370/wk37v3
payload plugin html preview
Live preview and click-to-edit in the Payload admin for any frontend that renders HTML, no framework needed
74451/wk37v3
payload plugin workflows
Code-defined editorial workflows with stages, actions, transitions and publish guards for editors and AI agents
73797/wk37v3
payload plugin scheduling
Schedule future publication of drafts on collections and globals with a secured cron endpoint
77783/wk37v3
payload plugin presets
Save and apply reusable block configurations as presets from the Payload admin blocks drawer
786.7k/wk37v3
payload plugin ab
A/B testing with page variants managed in the Payload admin and routed by Next.js middleware at the edge
741.0k/wk37v3