Lets an authorized user sign in as another user to see the site and admin as they do, for support and troubleshooting. The borrowed session is a real Payload session lasting one hour by default, and read-only mode refuses writes across collections, globals and jobs. Access is decided by a required canMasquerade callback and rechecked on every request. Requires Payload 3.80 or later, Next.js 15 or later, and a database with transactions.
Masquerade for Payload: admins sign in as another user, read-only, to see what they see, with a banner, a one-hour session, an admin-only user search and audit hooks.
Installation
npm i @extantape/payload-plugin-masq0
Stars
0
Forks
1
Open Issues
3 days ago
Last Updated
1.3k
Weekly Downloads
v0.1.8
npm Version
119.5 KB
Unpacked Size
0
Dependencies
00 since Oct 25
| Date | Stars |
|---|---|
| Dec 6, 2026 | 0 |
| Dec 5, 2026 | 0 |
| Dec 4, 2026 | 0 |
| Dec 3, 2026 | 0 |
| Dec 2, 2026 | 0 |
| Dec 1, 2026 | 0 |
| Nov 30, 2026 | 0 |
| Nov 29, 2026 | 0 |
| Nov 28, 2026 | 0 |
| Nov 27, 2026 | 0 |
| Nov 26, 2026 | 0 |
| Nov 25, 2026 | 0 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
| Nov 22, 2026 | 0 |
| Nov 21, 2026 | 0 |
| Nov 20, 2026 | 0 |
| Nov 19, 2026 | 0 |
| Nov 18, 2026 | 0 |
| Nov 17, 2026 | 0 |
| Nov 16, 2026 | 0 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 0 |
| Nov 13, 2026 | 0 |
| Nov 12, 2026 | 0 |
| Nov 11, 2026 | 0 |
| Nov 10, 2026 | 0 |
| Nov 9, 2026 | 0 |
| Nov 8, 2026 | 0 |
| Nov 7, 2026 | 0 |
| Nov 6, 2026 | 0 |
| Nov 5, 2026 | 0 |
| Nov 4, 2026 | 0 |
| Nov 3, 2026 | 0 |
| Nov 2, 2026 | 0 |
| Nov 1, 2026 | 0 |
| Oct 31, 2026 | 0 |
| Oct 30, 2026 | 0 |
| Oct 29, 2026 | 0 |
| Oct 28, 2026 | 0 |
| Oct 27, 2026 | 0 |
| Oct 26, 2026 | 0 |
| Oct 25, 2026 | 0 |
1.5K+1.3K since Nov 3
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 1,507 |
| Dec 5, 2026 | 1,522 |
| Dec 4, 2026 | 1,517 |
| Dec 3, 2026 | 1,481 |
| Dec 2, 2026 | 1,463 |
| Dec 1, 2026 | 1,270 |
| Nov 30, 2026 | 673 |
| Nov 29, 2026 | 549 |
| Nov 28, 2026 | 528 |
| Nov 27, 2026 | 361 |
| Nov 26, 2026 | 337 |
| Nov 25, 2026 | 314 |
| Nov 24, 2026 | 282 |
| Nov 23, 2026 | 242 |
| Nov 22, 2026 | 352 |
| Nov 21, 2026 | 322 |
| Nov 20, 2026 | 311 |
| Nov 19, 2026 | 276 |
| Nov 18, 2026 | 256 |
| Nov 17, 2026 | 230 |
| Nov 16, 2026 | 220 |
| Nov 15, 2026 | 0 |
| Nov 14, 2026 | 300 |
| Nov 13, 2026 | 275 |
| Nov 12, 2026 | 239 |
| Nov 11, 2026 | 222 |
| Nov 10, 2026 | 233 |
| Nov 9, 2026 | 336 |
| Nov 8, 2026 | 312 |
| Nov 7, 2026 | 281 |
| Nov 6, 2026 | 272 |
| Nov 5, 2026 | 234 |
| Nov 4, 2026 | 186 |
| Nov 3, 2026 | 186 |
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/1441337150-root)<a href="https://payloaddirectory.dev/plugins/1441337150-root"><img src="https://payloaddirectory.dev/badge/1441337150-root.svg" alt="Payload Directory"></a>README
Masquerade for Payload 3: an admin signs in as another user to see the site and admin exactly as they do, then returns to their own account with one click. Built for support and troubleshooting.
Beta (0.x). Used in production on a live site. Feedback and issues welcome.
/admin/masquerade): a "Masquerade as…" autocomplete for quick
switching, plus a user search with a Masquerade button on every result. Only people allowed to
masquerade see it, and the search reads with their own access, so it never lists anyone
they could not already see. The users list gets a Masquerade column with a button per row.<MasqueradeBanner />): who you are
masquerading as, the time left, and Return to my account. Once the borrowed session is
over, or you're no longer allowed to masquerade as that user, it names nobody and only offers
the way back.onStart (with an optional reason) and onStop, and masqueraderOf(req)
so your audit trail can record who really made a change./api/payload-jobs/run,
/api/payload-jobs/handle-schedules and through payload.jobs when you pass the request.
That holds over REST, GraphQL and the Local API when you pass the request. The borrowed token
itself is marked, so clearing the masquerade cookie doesn't lift it, whether the token comes
in the cookie or an Authorization header. Still allowed: reads, Payload's own bookkeeping
(preferences, document locks), signing in, signing out, and the plugin's own return. Not
covered: your own endpoints and server actions, and custom endpoints other plugins add (call
assertNotMasquerading(payload, headers) in yours), Local API calls made without the
request, writes made straight through payload.db or payload.kv, and email verification
links, which Payload runs without hooks.disableOnInit, the same check runs when a
masquerade starts and on every request with a borrowed session. If it later can't confirm it
(for example after a dev reload), start answers 503 "Masquerade is unavailable right now. The
server log says why." and the log says what was missing, and a running borrowed session signs
in as nobody until it's back.canMasquerade must answer exactly true. A truthy value, or an error it throws, is a
no: the endpoints refuse and the components show nothing.canMasquerade with no target isn't true for you,
start answers 403 for any id but your own that it won't let you use. If it is true, you get
404 "User not found." for a missing user, and for a refused user your own read access doesn't
find; a refused user you can read answers 403. So make canMasquerade answer true with no
target for the people who may use masquerade. A failure while loading the user is logged and
answered like a missing user.Authorization header, asks canMasquerade again with
phase: 'recheck' and the masquerader and the target loaded fresh, then your recheck if you
set one. See canMasquerade and phase below. If the answer
is no (the masquerader was demoted or deleted, or the target changed so the rule refuses),
the borrowed session is deleted on that request, the request runs signed out, and onStop
gets revoked: true. If the check itself fails (a read or the delete throws), the borrowed
token is ignored for that request, so it runs signed out. The cost is two reads by ID on
requests that carry a borrowed token. Every request that carries any token also has its token
signature checked once per auth strategy, with no extra reads; other requests cost nothing.onInit (Hats and MFA
do) can sit before Masq in plugins. At start-up, and again whenever the strategies change,
Masq confirms that calling the strategy Payload holds still runs the check and hands its
answer back unchanged; if not, Payload doesn't start, or start answers 503 and borrowed tokens
sign in as nobody. No strategy, in front of the check or after it, is handed a borrowed token
on a request the check hasn't finished, or once the headers it left have changed. The check
must come before Payload's own sign-in.recheck. recheck runs before anyone is signed in, so
req.user isn't set yet; use the masquerader and target it gets. The token is read from
the cookie even on cross-site requests, the same as Payload's own sign-in. Behind a Next.js
basePath, stopping a revoked masquerade can report onStop twice.onStop gets
expired: true only when that session had already ended. If Return can't confirm the session
ended, it answers 500, signs the browser out, sends it to the login page, skips onStop and
logs an error; the borrowed session then ends with its hour at the latest, and the per-request
check still covers it. Pressing Return again after it has finished reports onStop a second
time, with expired: true.allowNoTransactions: true is unsafe when requests overlap. It skips that check and lets
Masq change sessions without a transaction. Requests that arrive together can then undo each
other's changes to a user's sessions, so use it only on a single-user development database. On
a standalone MongoDB also set transactionOptions: false on the adapter.Nothing to run. After upgrading, start your app once and check that it starts. If it refuses with "read-only masquerade could not be put in place", the error lists what Masq couldn't guard; usually another plugin replaced hooks or access after start-up. Check any job runner, cron or hook of yours that runs, queues or cancels jobs with a request: while that request is masquerading, it now gets 403.
End running masquerades before upgrading. Each person masquerading can press Return to my account. To end them all at once, run the command under Upgrading from 0.1.0 below. It signs every user out.
Required, once: before or right after upgrading, end every running masquerade. Borrowed sessions started by 0.1.0 carry no mark, so with the masquerade cookie cleared they can still write, and Payload keeps refreshing them. There is no sound way to tell them apart from normal sessions afterwards. A borrowed session is stored on the target's account, so signing the masquerader out isn't enough. The commands below clear everyone's sessions, so every user is signed out once and signs in again. (Clearing only the masqueraded users' sessions would be enough, but no command for that is given here because none has been tested.)
With the Local API (any database adapter; tested), for the default users collection:
await payload.db.updateMany({ collection: 'users', where: {}, data: { sessions: [] } })
Or on MongoDB from the command line (the same change, not tested here):
mongosh "$DATABASE_URI" --eval 'db.users.updateMany({}, { $set: { sessions: [] } })'
From 0.1.2, Masq needs useSessions left out or set to true on its auth collection, because it
ends a borrowed token by deleting its session. Any other value (false, 0, an empty string)
stops the build. It checks again when Payload starts, so a plugin listed after Masq or a change
to the built config that turns sessions off stops start-up too. If sessions are off anyway, for
example when start-up checks were skipped, no borrowed token signs anyone in and no masquerade
can start. If you ran 0.1.0 or 0.1.1 that way, changing
PAYLOAD_SECRET is the only way to end the old tokens, and it signs everyone out.
On its own: it needs an auth collection (default users) with sessions on, which is Payload's default, and your canMasquerade. It doesn't need any other plugin. Auditing is up to your onStart and onStop.
Needs: Payload ^3.80.0, @payloadcms/next ^3.80.0, @payloadcms/ui ^3.80.0, Next.js >=15 and React >=19 as peer dependencies. No other EXTANT APE plugin is required.
Works with:
recordEvent from onStart and onStop (with masquerade in its actions), and use masqueraderOf(req) in its via so a change made while masquerading says who really made it.blocked(req) refuses switching while masquerading, and your canMasquerade refuses a switched session (hatsStateOf(user).via) when phase is 'start'. On 'recheck', user is read fresh from the database and carries no Hats state, so that check only means something at start.Color Theory: none yet. The masquerade banner and its return button use fixed colors (white on dark red), in the admin and on the site.
Family: It's part of the Identity family (a working draft): plugins designed to sit together for accounts and access.
npm install @extantape/payload-plugin-masq
import { masqPlugin } from '@extantape/payload-plugin-masq'
export default buildConfig({
plugins: [
masqPlugin({
// Required. Who may masquerade (target absent = may they use masquerade at all).
canMasquerade: ({ user, target }) => user.role === 'admin',
onStart: async ({ req, masquerader, target, reason }) => {
await req.payload.create({
collection: 'audit-log',
data: { action: 'masquerade-start', by: masquerader.id, user: target.id, reason },
req,
})
},
onStop: async ({ req, masqueraderId, targetId, expired, revoked }) => {
/* … */
},
}),
],
})
Then run payload generate:importmap. Add the banner to your site layout (a Server
Component) so masqueraders see it outside the admin too:
import { MasqueradeBanner } from '@extantape/payload-plugin-masq/rsc'
<MasqueradeBanner payload={payload} />
canMasquerade and phasecanMasquerade gets { payload, user, target?, phase }. Masq sets phase itself at every place
it asks; nothing in the request can change it.
'start': starting a masquerade, the search, the buttons, the Masquerade area and its
menu link, and the return to your own account. user is the user signed in on that request,
as your auth strategies built it. On the return, it is signed in from their own token alone,
without the request's other cookies; a no there signs them out instead of restoring them.'recheck': a borrowed session is running, on every request it makes and in the banner.
user is the masquerader read fresh from the database by ID. Anything your own auth strategy
only puts on req.user for a signed-in session, such as a second sign-in step or a switched
session, isn't there.Apply account rules (role, deny lists, anything stored on the account) in both phases. That is
what ends a masquerade when the masquerader is demoted or the target changes. Limit only
session-bound rules to 'start'; otherwise they fail on the first recheck and end every
masquerade.
Because those rules only run at 'start', losing the second sign-in step, or signing out of your
own account, leaves a running masquerade going until it expires or is stopped. If either should
end it, check it in recheck, for example against masquerader.sessions. And if the mark
travels in a request cookie or header, as in the example below, the return to your own account
won't see it, so it sends you to sign in again.
canMasquerade: ({ user, target, phase }) => {
// Account rules: both phases.
if (user.role !== 'admin' || target?.role === 'admin') return false
// Session-bound: only the signed-in session carries it, so only at start.
return phase === 'recheck' || user.secondStepDone === true
},
| Option | Default | |
|---|---|---|
canMasquerade | (required) | ({ payload, user, target?, phase }) => boolean. No default: nobody can masquerade until you decide. phase is 'start' or 'recheck'; see above. |
collection | 'users' | Auth collection. |
duration | 3600 | Seconds the borrowed session lasts. |
readOnly | true | Refuse create, update and delete while masquerading. |
requireReason | false | Ask for a reason; passed to onStart. |
labelField | 'email' | Name shown in the search and banner. |
searchFields | ['email'] | Fields the search matches. |
startPath | admin route | Where to go after starting. |
adminBanner | true | Banner in the admin header. |
adminView | true | Masquerade area and nav link. |
listColumn | true | Masquerade column in the users list (added to defaultColumns). |
allowNoTransactions | false | Start on a database that can't run transactions. Unsafe when requests overlap: see the limits above. |
recheck | ({ payload, req, masquerader, target }) => boolean, asked on every request a borrowed session makes, after canMasquerade with phase: 'recheck'. Only exactly true keeps the session; anything else, or a throw, ends it. Use it for checks canMasquerade doesn't make, such as a deny list. req.user isn't set yet. | |
onStart, onStop | Audit hooks. onStop gets revoked: true when the per-request check ended the session. | |
enabled | true |
On the auth collection (/api/users/…): POST /:id/masq (start, body { reason? }),
POST /masq/stop (return) and GET /masq/search?q= (admin search). All need a signed-in
user that canMasquerade allows. See How start answers a refusal
above.
payload-plugin-masquerade came first and is worth a look. We built this one because our direction differed in ways too large to merge: a short borrowed session that ends on return, restore only for a still-valid masquerader, an access-checked admin-only search, a banner on the site as well as the admin, and audit hooks.
MIT
payload plugin invitations
One-time emailed invitation links with hashed tokens, expiry, withdrawal and fail-closed rate limits
350v3
payload plugin sharing
Share records with users and organizations through groups with Owner, Manager and Viewer levels
76425/wk0v3
payload plugin positions
Scoped, dated position grants for users on a site, organization or project, with host-defined types and an audit trail
76382/wk0v3
payload plugin organizations
Organizations with member levels, approval of pending organizations, email-domain matching and an organization picker…
67596/wk0v3
multi tenant
Manage multiple tenants and tenant-scoped content from a single Payload admin panel
100165.4k/wk46.1kv3 v4
payload plugin guardians
Link minors to guardians, turn guardian edits into suggestions the minor decides, and route requests for approval
76366/wk0v3