Is there a way to hide a particular collection from admin sidebar for certain users?
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:
If a user doesn't have the right access, payload doesn't show the collection
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; }
Is there a way to achieve this dynamically, depending on the users role? I'd like specific collections to be only visible for admins
I think this is what you are looking for.
https://www.youtube.com/watch?v=DoPLyXG26Dg&t=483sUnfortunately not, I don't want to restrict access, just hide the collection from the dashboard and sidebar
I see 🤔
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?
},
Yes 100%, I’d love to see a similar pattern as with access control, it’s super dope!
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.
Yoooo @dribbens the man saving the day
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
Even easier: in the CollectionConfig, just add
admin: { hidden: true }
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.