-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Describe the Bug
Hello,
I'm trying to implement a logic where only certain users can use the unlock feature on a user.
At first I thought I could use a Where query since the unlock is from type Access.
Example:
access: {
unlock: (args) => {
return {
id: {
equals: args.req.user?.id,
},
}
},
},
This does not not have any effect and you can set any value for equals and you will see the unlock button.
My second attempt was to validate data from the args
Example:
access: {
unlock: (args) => {
return args.id === args.req.user?.id || args.data?.id === args.req.user?.id
},
},
But with this solution the button never appears because in one of the first calls args.data is null and therefor the result is false and the button disappear.
Im also not sure if this has anything to do with this line of code: https://github.com/payloadcms/payload/blob/main/packages/ui/src/views/Edit/Auth/index.tsx#L137
(Maybe I just don't understand this line of code)
Link to the code that reproduces this issue
https://github.com/tobidemski/payload-unlock-condition-bug
Reproduction Steps
HOW TO USE
- npm install
- npm run dev
- Go to: http://localhost:3000/admin
- Login
- User: admin@admin.de
- PW : admin
- Go to: http://localhost:3000/admin/collections/users/1
- Check "Force unlock" not present
- Try using any condition based on some args data. (Use case: Only allow unlock on certain users)
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Binaries:
Node: 22.17.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant Packages:
payload: 3.62.1
next: 15.4.4
@payloadcms/db-sqlite: 3.62.1
@payloadcms/drizzle: 3.62.1
@payloadcms/email-nodemailer: 3.62.1
@payloadcms/graphql: 3.62.1
@payloadcms/next/utilities: 3.62.1
@payloadcms/payload-cloud: 3.62.1
@payloadcms/richtext-lexical: 3.62.1
@payloadcms/translations: 3.62.1
@payloadcms/ui/shared: 3.62.1
react: 19.1.0
react-dom: 19.1.0
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 32510
Available CPU cores: 16