Adds endpoints and an admin sidebar user selector that let authorized administrators impersonate another user in an auth collection. Starting a session issues a token for the target user and stores a signed cookie with the original user, so the admin can switch back. Works with Payload 3.44 or newer and offers callbacks for authorization and audit logging.
Masquerade user for Payload CMS
Installation
npm i payload-plugin-masquerade30
Stars
2
Forks
1
Open Issues
3 weeks ago
Last Updated
83
Weekly Downloads
v2.1.1
npm Version
85.4 KB
Unpacked Size
0
Dependencies
300 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 30 |
| Dec 5, 2026 | 30 |
| Dec 4, 2026 | 30 |
| Dec 3, 2026 | 30 |
| Dec 2, 2026 | 30 |
| Dec 1, 2026 | 30 |
| Nov 30, 2026 | 30 |
| Nov 29, 2026 | 30 |
| Nov 28, 2026 | 30 |
| Nov 27, 2026 | 30 |
| Nov 26, 2026 | 30 |
| Nov 25, 2026 | 30 |
| Nov 24, 2026 | 30 |
| Nov 23, 2026 | 30 |
| Nov 22, 2026 | 30 |
| Nov 21, 2026 | 30 |
| Nov 20, 2026 | 30 |
| Nov 19, 2026 | 30 |
| Nov 18, 2026 | 30 |
| Nov 17, 2026 | 30 |
| Nov 16, 2026 | 30 |
| Nov 15, 2026 | 30 |
| Nov 14, 2026 | 30 |
| Nov 13, 2026 | 30 |
| Nov 12, 2026 | 30 |
| Nov 11, 2026 | 30 |
| Nov 10, 2026 | 30 |
| Nov 9, 2026 | 30 |
| Nov 8, 2026 | 30 |
| Nov 7, 2026 | 30 |
| Nov 6, 2026 | 30 |
| Nov 5, 2026 | 30 |
| 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 | 30 |
| Oct 23, 2026 | 30 |
| Oct 22, 2026 | 30 |
| Oct 21, 2026 | 30 |
| Oct 20, 2026 | 30 |
| Oct 19, 2026 | 30 |
| Oct 18, 2026 | 30 |
| Oct 17, 2026 | 30 |
| Oct 16, 2026 | 30 |
| Oct 15, 2026 | 30 |
| Oct 14, 2026 | 30 |
| Oct 13, 2026 | 30 |
| Oct 12, 2026 | 30 |
| Oct 11, 2026 | 30 |
| Oct 10, 2026 | 30 |
| Oct 9, 2026 | 30 |
| Oct 8, 2026 | 30 |
| Oct 7, 2026 | 30 |
| Oct 6, 2026 | 30 |
| Oct 5, 2026 | 30 |
| Oct 4, 2026 | 30 |
| Oct 3, 2026 | 30 |
| Oct 2, 2026 | 30 |
| Oct 1, 2026 | 30 |
| Sep 30, 2026 | 30 |
| Sep 29, 2026 | 30 |
| Sep 28, 2026 | 30 |
| Sep 27, 2026 | 30 |
| Sep 26, 2026 | 30 |
| Sep 25, 2026 | 30 |
| Sep 24, 2026 | 30 |
| Sep 23, 2026 | 30 |
| Sep 22, 2026 | 30 |
| Sep 21, 2026 | 30 |
| Sep 20, 2026 | 30 |
| Sep 19, 2026 | 30 |
| Sep 18, 2026 | 30 |
| Sep 17, 2026 | 30 |
| Sep 16, 2026 | 30 |
| Sep 15, 2026 | 30 |
| Sep 14, 2026 | 30 |
| Sep 13, 2026 | 30 |
| Sep 12, 2026 | 30 |
| Sep 11, 2026 | 30 |
| Sep 10, 2026 | 30 |
| Sep 9, 2026 | 30 |
| Sep 8, 2026 | 30 |
| Sep 7, 2026 | 30 |
158+95 since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 158 |
| Dec 5, 2026 | 212 |
| Dec 4, 2026 | 231 |
| Dec 3, 2026 | 246 |
| Dec 2, 2026 | 248 |
| Dec 1, 2026 | 212 |
| Nov 30, 2026 | 232 |
| Nov 29, 2026 | 169 |
| Nov 28, 2026 | 120 |
| Nov 27, 2026 | 112 |
| Nov 26, 2026 | 108 |
| Nov 25, 2026 | 100 |
| Nov 24, 2026 | 101 |
| Nov 23, 2026 | 84 |
| Nov 22, 2026 | 71 |
| Nov 21, 2026 | 85 |
| Nov 20, 2026 | 250 |
| Nov 19, 2026 | 315 |
| Nov 18, 2026 | 426 |
| Nov 17, 2026 | 462 |
| Nov 16, 2026 | 466 |
| Nov 15, 2026 | 468 |
| Nov 14, 2026 | 452 |
| Nov 13, 2026 | 289 |
| Nov 12, 2026 | 233 |
| Nov 11, 2026 | 148 |
| Nov 10, 2026 | 120 |
| Nov 9, 2026 | 133 |
| Nov 8, 2026 | 138 |
| Nov 7, 2026 | 133 |
| Nov 6, 2026 | 122 |
| Nov 5, 2026 | 122 |
| Nov 4, 2026 | 101 |
| Nov 3, 2026 | 92 |
| Nov 2, 2026 | 74 |
| Nov 1, 2026 | 94 |
| Oct 31, 2026 | 96 |
| Oct 30, 2026 | 106 |
| Oct 29, 2026 | 80 |
| Oct 28, 2026 | 69 |
| Oct 27, 2026 | 77 |
| Oct 26, 2026 | 142 |
| Oct 25, 2026 | 158 |
| Oct 24, 2026 | 188 |
| Oct 23, 2026 | 171 |
| Oct 22, 2026 | 209 |
| Oct 21, 2026 | 281 |
| Oct 20, 2026 | 309 |
| Oct 19, 2026 | 308 |
| Oct 18, 2026 | 289 |
| Oct 17, 2026 | 283 |
| Oct 16, 2026 | 355 |
| Oct 15, 2026 | 355 |
| Oct 14, 2026 | 485 |
| Oct 13, 2026 | 630 |
| Oct 12, 2026 | 743 |
| Oct 11, 2026 | 838 |
| Oct 10, 2026 | 846 |
| Oct 9, 2026 | 898 |
| Oct 8, 2026 | 905 |
| Oct 7, 2026 | 741 |
| Oct 6, 2026 | 586 |
| Oct 5, 2026 | 449 |
| Oct 4, 2026 | 347 |
| Oct 3, 2026 | 378 |
| Oct 2, 2026 | 334 |
| Oct 1, 2026 | 312 |
| Sep 30, 2026 | 310 |
| Sep 29, 2026 | 330 |
| Sep 28, 2026 | 312 |
| Sep 27, 2026 | 300 |
| Sep 26, 2026 | 237 |
| Sep 25, 2026 | 179 |
| Sep 24, 2026 | 167 |
| Sep 23, 2026 | 147 |
| Sep 22, 2026 | 144 |
| Sep 21, 2026 | 118 |
| Sep 20, 2026 | 112 |
| Sep 19, 2026 | 108 |
| Sep 18, 2026 | 107 |
| Sep 17, 2026 | 121 |
| Sep 16, 2026 | 146 |
| Sep 15, 2026 | 103 |
| Sep 14, 2026 | 104 |
| Sep 13, 2026 | 103 |
| Sep 12, 2026 | 117 |
| Sep 11, 2026 | 97 |
| Sep 10, 2026 | 101 |
| Sep 9, 2026 | 64 |
| Sep 8, 2026 | 63 |
| Sep 7, 2026 | 63 |
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/855845541-root)<a href="https://payloaddirectory.dev/plugins/855845541-root"><img src="https://payloaddirectory.dev/badge/855845541-root.svg" alt="Payload Directory"></a>README
The Masquerade plugin allows administrators to switch users and surf the site as that user (no password required). Administrators can switch back to their own user account at any time.

Choose your package manager:
# pnpm
pnpm add payload-plugin-masquerade
# npm
npm install payload-plugin-masquerade
# yarn
yarn add payload-plugin-masquerade
Add the plugin to your Payload configuration:
import { masqueradePlugin } from 'payload-plugin-masquerade'
import { buildConfig } from 'payload'
export default buildConfig({
// ... your other config
plugins: [
masqueradePlugin({
// Optional: specify auth collection (defaults to 'users')
authCollection: 'users',
// Optional: enable/disable admin form (defaults to true)
enableBlockForm: true,
// Optional: enable/disable plugin (defaults to true)
enabled: true,
}),
],
})
| Option | Type | Default | Description |
|---|---|---|---|
authCollection | string | 'users' | Slug of the collection used for authentication |
enableBlockForm | boolean | true | Adds user selection block in Admin UI (beforeNavLinks) |
enabled | boolean | true | Enables/disables the entire plugin |
onMasquerade | function | undefined | Async callback called when starting masquerade |
onUnmasquerade | function | undefined | Async callback called when ending masquerade |
canMasquerade | function | admin role check | Authorizes starting masquerade |
canUnmasquerade | function | true | Authorizes ending masquerade |
userLabelField | string | 'email' | Field displayed in the admin user selector |
targetUserWhere | Where | undefined | Optional Payload where clause for selector targets |
import { masqueradePlugin } from 'payload-plugin-masquerade'
export default buildConfig({
plugins: [
masqueradePlugin({
authCollection: 'users',
enableBlockForm: true,
enabled: true,
canMasquerade: async ({ req, targetUser }) => {
return req.user?.roles?.includes('admin') && req.user.id !== targetUser.id
},
onMasquerade: async ({ req, originalUserId, targetUserId }) => {
// req.user contains the original admin user
console.log(`Admin ${req.user?.email} started masquerading as user ${targetUserId}`)
// Example: Log to audit collection
await req.payload.create({
collection: 'auditLogs',
data: {
action: 'masquerade_start',
adminId: originalUserId,
targetUserId,
timestamp: new Date(),
},
})
},
onUnmasquerade: async ({ req, originalUserId, targetUserId }) => {
// req.user contains the user we were masquerading as
console.log(`Ending masquerade, returning to user ${originalUserId}`)
// Example: Log audit trail
await req.payload.create({
collection: 'auditLogs',
data: {
action: 'masquerade_end',
adminId: originalUserId,
masqueradeUserId: targetUserId,
timestamp: new Date(),
},
})
},
}),
],
})
The plugin adds a user selection form to the admin interface that appears before the navigation links:

To disable the admin form:
masqueradePlugin({
enableBlockForm: false,
})
The plugin automatically adds these endpoints to your API:
POST /api/<authCollection>/:id/masquerade
Behavior:
payload-masquerade cookie with original and target user IDs/adminExample:
curl -i -X POST "http://localhost:3000/api/users/USER_ID/masquerade"
POST /api/<authCollection>/unmasquerade
Behavior:
payload-masquerade cookie/adminExample:
curl -i -X POST "http://localhost:3000/api/users/unmasquerade"
Called when masquerade session starts:
onMasquerade: async ({ req, originalUserId, targetUserId, targetUser }) => {
// req: PayloadRequest (req.user is the original admin)
// originalUserId: ID of the original user
// targetUserId: ID of user being masqueraded
// targetUser: target user document
}
Called when masquerade session ends:
onUnmasquerade: async ({ req, originalUserId, targetUserId }) => {
// req: PayloadRequest (req.user is the masqueraded user)
// originalUserId: ID of the original admin user
// targetUserId: ID of the masqueraded user
}
⚠️ Security Warning: Masquerade functionality allows administrators to access user accounts without passwords. Follow these best practices:
onMasquerade: async ({ req, originalUserId, targetUserId }) => {
await req.payload.create({
collection: 'securityLogs',
data: {
action: 'masquerade',
adminId: originalUserId,
targetId: targetUserId,
ipAddress: req.ip,
userAgent: req.headers['user-agent'],
timestamp: new Date(),
},
})
}
To contribute or run the plugin locally:
Clone the repository
git clone https://github.com/manutepowa/payload-plugin-masquerade.git
cd payload-plugin-masquerade
Install dependencies
pnpm install
Set up development environment
cp dev/.env.example dev/.env
# Edit dev/.env with your database configuration
Start development servers
pnpm dev
Visit the admin Open http://localhost:3000/admin
# Run all tests
pnpm test
# Run integration tests only
pnpm test:int
# Run E2E tests only
pnpm test:e2e
Cause: The authCollection option doesn't match any registered collection.
Solutions:
buildConfig.collectionsCause: The enableBlockForm option might be disabled.
Solution:
masqueradePlugin({
enableBlockForm: true, // Make sure this is true
})
Cause: Session conflicts or cookie issues.
Solutions:
The MIT License (MIT). Please see License File for more information.
Topics
payload totp
Add TOTP-based two-factor authentication to a Payload auth collection using authenticator apps
8425.1k/wk168v3
payload keycloak
Keycloak SSO-only authentication for Payload 3 using OIDC with PKCE and permission-based access helpers
5511/wk0v3
payload auth cookie
Authenticate Payload admin and app users from cookies set by an external SSO system
7683/wk4v3
payload zitadel plugin
Log in to the Mzinga admin through Zitadel or another OIDC provider using authorization code with PKCE
72608/wk11v?
payload auth
Replace Payload's built-in auth with Better Auth for a shared admin and frontend session
7021.0k/wk349v3
password policy
Configurable, localized password strength rules for Payload auth collections
69690/wk0v3