Hide Collection from admin sidebar

default discord avatar
nacho
last month
17

Is there a way to hide a particular collection from admin sidebar for certain users?

  • default discord avatar
    akacronos
    last month

    you can do it changing the access to the collection and limit the read function to certain users roles:


    Docs:

    https://payloadcms.com/docs/access-control/collections


    Here the example:


    https://payloadcms.com/docs/access-control/collections#read

    If a user doesn't have the right access, payload doesn't show the collection

  • default discord avatar
    nacho
    last month

    I just wanted to hide the collection from the admin, not restrict access. Didn't express myself correctly.



    Just found the solution on another post. Just add css to hide that element, for example, here I'm hiding users collection:



    .dashboard__card-list li:has(#card-users), #nav-users { display: none; }
  • default discord avatar
    Sandro Wegmann
    last week

    Is there a way to achieve this dynamically, depending on the users role? I'd like specific collections to be only visible for admins

  • default discord avatar
    Eustachio
    last week

    I think this is what you are looking for.

    https://www.youtube.com/watch?v=DoPLyXG26Dg&t=483s
  • default discord avatar
    Sandro Wegmann
    last week

    Unfortunately not, I don't want to restrict access, just hide the collection from the dashboard and sidebar

  • default discord avatar
    Eustachio
    last week

    I see 🤔

  • default discord avatar
    thisisnotchris
    last week

    It would be cool to see visibility controls on the admin config for a global/collection that would handle this by role



      admin: {
        group: "Pages",
        visibility: [Users] // or role property on a user collection?
      },
  • default discord avatar
    Sandro Wegmann
    last week

    Yes 100%, I’d love to see a similar pattern as with access control, it’s super dope!

  • discord user avatar
    dribbens
    Payload Team
    6 days ago

    You can dynamically hide collections and globals from the admin outside of access control also using

    admin.hidden

    as a function.



          admin: {
            hidden: ({ user }) => user.role !== 'admin',
          },


    Something like that will work, assuming you have a

    role

    property on your users.



    @Sandro Wegmann @thisisnotchris @Eustachio @nacho @akacronos


    I'm tagging you because I am sad nobody knew this.

  • default discord avatar
    thisisnotchris
    6 days ago

    Yoooo @dribbens the man saving the day

  • default discord avatar
    Sandro Wegmann
    6 days ago

    Haha maybe that’s the only disadvantage of a great community, you’re always tempted to just post a question in the forum instead of really getting your hands dirty first

  • default discord avatar
    Above The Clouds
    6 days ago

    Even easier: in the CollectionConfig, just add

    admin: { hidden: true }
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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