what-works-global

audit fields

by what-works-global
payload-packages
Logging & monitoring
v3
>=3.27.0 <4

Overview

Summary generated from the README

Adds read-only createdBy and lastModifiedBy relationship fields to collections and globals, set automatically from the acting user. Replaces the versions list view with a recreation that adds a per-version Modified By column. Requires Payload 3.27 or later and regenerating the import map.

Features

  • Adds createdBy and lastModifiedBy fields to all collections and globals by default
  • Include or exclude specific collections and globals
  • Shows attributed users as linked labels, customizable with resolveUserLabel
  • Enhanced versions view with a Modified By column
  • Supports multiple auth collections via polymorphic references
  • Custom attribution through resolveUser for jobs and webhooks

Use cases

  • Show editors who last changed a document in list and edit views
  • Review which user saved each version in the versions history
  • Attribute automated job or seed writes to a dedicated system user

From the author

Payload plugin that tracks who created and last modified every document, with an enhanced versions view showing who modified each version.

Installation

npm i @whatworks/payload-audit-fields

16

Stars

1

Forks

2

Open Issues

3 days ago

Last Updated

176

Weekly Downloads

v0.2.0

npm Version

141.2 KB

Unpacked Size

0

Dependencies

Repository stars

16+1 since Sep 7

Show data
Repository stars by day (UTC)
DateStars
Dec 6, 202616
Dec 5, 202616
Dec 4, 202616
Dec 3, 202616
Dec 2, 202616
Dec 1, 202616
Nov 30, 202616
Nov 29, 202616
Nov 28, 202616
Nov 27, 202616
Nov 26, 202616
Nov 25, 202616
Nov 24, 202616
Nov 23, 202616
Nov 22, 202616
Nov 21, 202616
Nov 20, 202616
Nov 19, 202616
Nov 18, 202616
Nov 17, 202615
Nov 16, 202615
Nov 15, 202615
Nov 14, 202615
Nov 13, 202615
Nov 12, 202615
Nov 11, 202615
Nov 10, 202615
Nov 9, 202615
Nov 8, 202615
Nov 7, 202615
Nov 6, 202615
Nov 5, 202615
Nov 4, 202615
Nov 3, 202615
Nov 2, 202615
Nov 1, 202615
Oct 31, 202615
Oct 30, 202615
Oct 29, 202615
Oct 28, 202615
Oct 27, 202615
Oct 26, 202615
Oct 25, 202615
Oct 24, 202615
Oct 23, 202615
Oct 22, 202615
Oct 21, 202615
Oct 20, 202615
Oct 19, 202615
Oct 18, 202615
Oct 17, 202615
Oct 16, 202615
Oct 15, 202615
Oct 14, 202615
Oct 13, 202615
Oct 12, 202615
Oct 11, 202615
Oct 10, 202615
Oct 9, 202615
Oct 8, 202615
Oct 7, 202615
Oct 6, 202615
Oct 5, 202615
Oct 4, 202615
Oct 3, 202615
Oct 2, 202615
Oct 1, 202615
Sep 30, 202615
Sep 29, 202615
Sep 28, 202615
Sep 27, 202615
Sep 26, 202615
Sep 25, 202615
Sep 24, 202615
Sep 23, 202615
Sep 22, 202615
Sep 21, 202615
Sep 20, 202615
Sep 19, 202615
Sep 18, 202615
Sep 17, 202615
Sep 16, 202615
Sep 15, 202615
Sep 14, 202615
Sep 13, 202615
Sep 12, 202615
Sep 11, 202615
Sep 10, 202615
Sep 9, 202615
Sep 8, 202615
Sep 7, 202615

Shared by 12 plugins in what-works-global/payload-packages.

npm weekly downloads

217+202 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026217
Dec 5, 2026263
Dec 4, 2026297
Dec 3, 2026266
Dec 2, 2026271
Dec 1, 2026300
Nov 30, 2026297
Nov 29, 2026254
Nov 28, 2026201
Nov 27, 2026157
Nov 26, 2026161
Nov 25, 2026176
Nov 24, 2026190
Nov 23, 2026190
Nov 22, 2026218
Nov 21, 2026224
Nov 20, 2026310
Nov 19, 2026277
Nov 18, 2026343
Nov 17, 2026302
Nov 16, 2026311
Nov 15, 2026318
Nov 14, 2026347
Nov 13, 2026299
Nov 12, 2026292
Nov 11, 2026247
Nov 10, 2026278
Nov 9, 2026279
Nov 8, 2026257
Nov 7, 2026232
Nov 6, 2026200
Nov 5, 2026200
Nov 4, 2026193
Nov 3, 2026167
Nov 2, 2026157
Nov 1, 2026142
Oct 31, 2026124
Oct 30, 2026117
Oct 29, 202689
Oct 28, 202623
Oct 27, 202620
Oct 26, 202623
Oct 25, 202628
Oct 24, 202628
Oct 23, 202620
Oct 22, 202634
Oct 21, 202642
Oct 20, 202637
Oct 19, 202634
Oct 18, 202639
Oct 17, 202673
Oct 16, 202673
Oct 15, 202662
Oct 14, 202664
Oct 13, 202663
Oct 12, 202662
Oct 11, 202675
Oct 10, 202647
Oct 9, 202665
Oct 8, 202665
Oct 7, 202660
Oct 6, 202664
Oct 5, 202664
Oct 4, 202639
Oct 3, 202641
Oct 2, 202623
Oct 1, 202633
Sep 30, 202630
Sep 29, 202626
Sep 28, 202626
Sep 27, 202628
Sep 26, 202622
Sep 25, 202624
Sep 24, 202616
Sep 23, 202627
Sep 22, 202629
Sep 21, 202632
Sep 20, 202632
Sep 19, 202632
Sep 18, 202632
Sep 17, 202628
Sep 16, 202616
Sep 15, 202614
Sep 14, 202611
Sep 13, 20269
Sep 12, 20267
Sep 11, 20267
Sep 10, 202611
Sep 9, 202612
Sep 8, 202613
Sep 7, 202615

Each point is npm's rolling 7-day download count.

Health Score

62/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1064440892-audit-fields.svg)](https://payloaddirectory.dev/plugins/1064440892-audit-fields)
HTML
<a href="https://payloaddirectory.dev/plugins/1064440892-audit-fields"><img src="https://payloaddirectory.dev/badge/1064440892-audit-fields.svg" alt="Payload Directory"></a>
Updated Dec 2, 2026Created Sep 26, 2025Published Jul 17, 2026

README

@whatworks/payload-audit-fields

@whatworks/payload-audit-fields

 

Payload plugin that records who created and who last modified every document, and upgrades the versions list view with a Modified By column so you can see exactly who saved each version.

  • Adds read-only createdBy / lastModifiedBy relationship fields to every collection and global by default (opt-out, not opt-in).
  • Displays attributed users by email (customizable via resolveUserLabel) — on the document, in the collection list view, and in the versions view — linked to the user document.
  • Replaces the versions list view with a faithful recreation of Payload's own view, extended with a per-version "Modified By" column.
  • Supports multiple auth collections — attribution is stored as a polymorphic reference to whichever collection the acting user belongs to.
  • Data-compatible with @payload-bites/audit-fields — same default field names and the same stored value shape ({ relationTo, value }), so you can switch plugins without a migration.

Demo

Audit fields in a collection list

Audit fields on a document

Modified By column in the versions view

Installation

pnpm add @whatworks/payload-audit-fields

Usage

import { auditFieldsPlugin } from '@whatworks/payload-audit-fields'
import { buildConfig } from 'payload'

export default buildConfig({
  // ...
  plugins: [
    // Register last so collections added by other plugins are audited too.
    auditFieldsPlugin(),
  ],
})

Then regenerate the import map so the admin panel can resolve the plugin's components:

payload generate:importmap

That's it — every collection and global now tracks createdBy and lastModifiedBy, and every entity with versions enabled gets the enhanced versions view.

Options

auditFieldsPlugin({
  // Which collections to audit. Defaults to all.
  // - true — every collection (default)
  // - ['posts', 'pages'] — only these
  // - { exclude: ['tags'] } — all except these
  collections: { exclude: ['tags'] },

  // Which globals to audit. Same semantics. Defaults to all.
  globals: true,

  // Auth collections users can be attributed to.
  // Defaults to every auth-enabled collection in your config.
  userCollections: ['users'],

  fields: {
    createdBy: {
      name: 'createdBy',
      label: 'Created By', // string | { [locale]: string } | (slug) => label
      // Escape hatch for full control over the generated field, e.g. delete
      // `field.admin.components` to restore the default relationship input:
      override: (field) => ({ ...field, index: true }),
    },
    // Set to false to only track one of the two fields:
    lastModifiedBy: { name: 'lastModifiedBy', label: 'Last Modified By' },
  },

  showInSidebar: false, // default false — fields render at the end of the main field area
  index: false, // default false — add a DB index to the fields

  // Custom attribution, e.g. attribute job/webhook writes to a bot user.
  // Return null/undefined to leave the fields untouched for that change.
  resolveUser: ({ req }) =>
    req.user ? { relationTo: req.user.collection, value: req.user.id } : null,

  // How attributed users are displayed — on the document and in the versions
  // view. May be async. Defaults to email → username → ID.
  resolveUserLabel: ({ user }) =>
    user.firstName ? `${user.firstName} ${user.lastName}` : (user.email as string),

  // The enhanced versions list view. Default: true.
  versionsView: {
    columnLabel: 'Modified By', // string | { [locale]: string }
  },
  // ...or `versionsView: false` to keep Payload's default view.
})

Behaviour

  • Create sets both createdBy and lastModifiedBy to the acting user.
  • Update sets lastModifiedBy and strips any incoming createdBy value, so API clients cannot rewrite attribution after the fact.
  • Writes without a user (seeds, migrations, job runners, local API calls without user/req) leave both fields untouched, so scripts can set them explicitly when needed — or use resolveUser to attribute them to a dedicated system user.
  • If an entity already defines a field with one of the configured names, the plugin leaves that entity's field and its values entirely alone.
  • The plugin does not touch Payload's internal collections (payload-preferences, payload-migrations, payload-locked-documents, payload-folders, …) — they are created after plugins run, are system-managed, or already carry their own user reference.

How users are displayed

On the document, audit fields render as a read-only label linking to the user document instead of the default (greyed-out) relationship input. The collection list view shows the same label in place of the raw relationship ID, and the versions view's "Modified By" column shows it too.

All three use resolveUserLabel to derive the label from the user document, which is fetched with the viewing user's access rights — if the current user cannot read the users collection, the raw ID is shown instead. The default resolver returns user.email, falling back to user.username, then the ID.

resolveUserLabel may be async, so you can derive the label from anywhere:

resolveUserLabel: async ({ relationTo, req, user }) => {
  const profile = await req.payload.findByID({ collection: 'profiles', id: user.profile })
  return profile?.displayName ?? (user.email as string)
}

Versions view

For every audited entity with versions enabled, the plugin sets admin.components.views.edit.versions to its own server view (@whatworks/payload-audit-fields/rsc#AuditVersionsView) — unless you have already customized that view, in which case yours wins.

The view is a faithful recreation of Payload's built-in versions list (same layout, pagination, status pills, autosave badges, and trash support), with one addition: a Modified By column showing who saved each version, linked to the user document. It reads lastModifiedBy from each version snapshot and falls back to createdBy for the initial version.

The vendored view internals come from [email protected] and degrade gracefully on the older Payload versions in the peer range (version-gated props are simply absent there); if Payload materially changes its versions view, update the vendored files alongside the peer bump.

Migrating from @payload-bites/audit-fields

Field names, labels, and the stored value shape are identical by default, so swapping plugins requires no data migration. Differences to be aware of:

  • lastModifiedBy is now also set on create (previously only on update).
  • createdBy can no longer be overwritten through authenticated API updates.
  • Audit fields render at the end of the main field area by default; pass showInSidebar: true for the old placement.
  • Fields display the user's email as a link instead of a disabled relationship input (customize via resolveUserLabel, or restore the input via fields.createdBy.override).
  • excludedCollections / excludedGlobals become collections: { exclude: [...] } / globals: { exclude: [...] }.
  • Attribution uses req.user.collection, so users from any auth collection are recorded correctly (previously always the admin user collection).

Similar plugins