payload
payload copied to clipboard
TypeError: Cannot read properties of undefined (reading 'endSession')
Link to reproduction
https://github.com/LorenzoInvernizzi/issue-endsession-undefined-update-access
Describe the Bug
Hi Devs,
I encountered the error in the following situation: edit of a collection item (Timecards collection) with the following access function for create & edit:
Basically i have the following collections:
- users: admin or developers, developers must be able to login and create/view/edit their own timecards
- clients
- projects
- timecard: submitted by devs, here i am using the access function and this is the place where i get the error when i try to edit an existing timecard. Actually i am not able to edit the timecard at all, i think it is related to the issue.
- i also created another access function (isAdminOrDeveloper) where i was able to implement a workaround but it involves querying the db with the local api
To Reproduce
- clone repo, setup .env file with mongodbatlas db or a local mongodb
- yarn dev and create admin
- create developer user from admin panel
- create a client and a project from the admin panel
- logout and login with dev account
- create timecard with dev account
- try to edit timecard with dev account -> get error
Payload Version
^2.1.1
Adapters and Plugins
bundler-vite, db-mongodb
I am running into the same error message for similar cases in several of my collections. After some testing, it seems like it triggers on field access functions if one field has more than a single access function, or if two or more fields have one or more access functions. I'm using the MongoDB adapter. It looks like the transaction is being shut down prematurely.
Here is example code to explain when the error triggers in my app:
const isSuperuser = (args) => args.req.user.superuser;
// No error
{
fields: [
{ name: 'fieldOne', type: 'text', access: { create: isSuperuser, } },
{ name: 'fieldTwo', type: 'text' }
]
}
// Error
{
fields: [
{ name: 'fieldOne', type: 'text', access: { create: isSuperuser, update: isSuperuser } },
{ name: 'fieldTwo', type: 'text' }
]
}
// Error
{
fields: [
{ name: 'fieldOne', type: 'text', access: { create: isSuperuser } },
{ name: 'fieldTwo', type: 'text', access: { create: isSuperuser } }
]
}
Getting this same error with v2.1.1. Reverting to v2.1.0 fixes the issue.
Getting this same error with v2.1.1. Reverting to v2.1.0 fixes the issue.
2.1.0 fixes it thanks!
@peterskeide explains it perfectly. With one field access it works, with more than one I get this error:
and all the fields of the collections become readonly / uneditable.
Commenting again to add that I don't have any field-level access checks, but I do have multiple (create, read, update, delete) collection-level access checks.
Same issue here. This only happens when there are field level access control checks on the collection.
Can confirm, I'm still having unauthorized issues with 2.2.2. Staying at 2.1.0 is the only solution so far that I'm aware of.
I'm closing this as it has become stale. Tag me if this is still an issue and we can re-open it.