Using User object in Conditional Logic

default discord avatar
7 months ago

According to the documentation here

one should be able to access the User object in the condition - show/hide field based on user data.

When I copy the example into my code, I get the following error.

Type '(data: any, siblingData: any, { user }: { user: any; }) => boolean' is not assignable to type 'Condition<any, any>'

Is the documentation actual, or am I doing something wrong. Here is my code (inside tabs, inside row):

  name: 'sourceAsset',
  label: 'Offset Account',
  type: 'relationship',
  relationTo: 'assets',
  admin: {
    description: 'Some description',
    condition: (data, siblingData, { user }) => { //<--- ERROR
      return true;
  access: {
    create: isAssetManagerFieldLevel,
    update: isAssetManagerFieldLevel,
    read: isLoggedInFieldLevel,
  filterOptions: ({ relationTo, data }) => {
    return {...}

When I escape this error with ts-ignore, then I get the following runtime error:

caught (in promise) TypeError: Cannot read properties of undefined (reading 'user')
  • default discord avatar
    6 months ago

    I'm currently also struggling with this

    Within the condition type user is also not defined

    export type Condition<T extends TypeWithID = any, P = any> = (data: Partial<T>, siblingData: Partial<P>) => boolean;

    But it is included within docs and @dribbens added this from discussion

    with PR
  • default discord avatar
    6 months ago

    Just to rule out the obvious, your Payload version is > 1.7.2, right?

  • discord user avatar
    Payload Team
    6 months ago

    The condition change should be in place for all field types. It has to be that you're on an older version of Payload as Tinouti suggested. If you're seeing this on @latest, I would create an issue on github.

  • default discord avatar
    6 months ago

    @tinouti @dribbens thanks 🙏 and sorry, it was my mistake 🙈

    I thought I was sure I had a version after this merge date 🤦‍♂️

  • default discord avatar
    6 months ago

    Haha, glad to hear this was all this was! 🙌

  • default discord avatar
    4 months ago


Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.