Skip to content

TypeError: Cannot read properties of undefined (reading 'endSession') #4133

Closed

Description

@LorenzoInvernizzi

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:
image

image

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

  1. clone repo, setup .env file with mongodbatlas db or a local mongodb
  2. yarn dev and create admin
  3. create developer user from admin panel
  4. create a client and a project from the admin panel
  5. logout and login with dev account
  6. create timecard with dev account
  7. try to edit timecard with dev account -> get error

Payload Version

^2.1.1

Adapters and Plugins

bundler-vite, db-mongodb

Activity

  1. added
    status: needs-triage
    on Nov 14, 2023
  2. peterskeide commented on Nov 15, 2023

    @peterskeide

    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 } }
      ]
    }
  3. revnelson commented on Nov 15, 2023

    @revnelson

    Getting this same error with v2.1.1. Reverting to v2.1.0 fixes the issue.

  4. billyhawkes commented on Nov 16, 2023

    @billyhawkes

    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:
    image
    and all the fields of the collections become readonly / uneditable.

  5. self-assigned this
    on Nov 16, 2023
  6. revnelson commented on Nov 17, 2023

    @revnelson

    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.

  7. jasperverbeet commented on Nov 20, 2023

    @jasperverbeet

    Same issue here. This only happens when there are field level access control checks on the collection.

  8. revnelson commented on Nov 30, 2023

    @revnelson

    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.

  9. added
    db: mongodb
    on Dec 27, 2023
  10. DanRibbens commented on Jul 22, 2024

    @DanRibbens
    Contributor

    I'm closing this as it has become stale. Tag me if this is still an issue and we can re-open it.

  11. removed
    status: needs-triage
    on Jul 22, 2024
  12. github-actions commented on Sep 7, 2024

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  13. locked as resolved and limited conversation to collaborators on Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

db: mongodb

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions