#hide "API" tab for some users
9 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
I found a way but it's quite hacky, I wonder if there is a better way.
import { tabs } from 'payload/dist/admin/components/elements/DocumentHeader/Tabs/tabs'
import { useAuth } from 'payload/dist/admin/components/utilities/Auth'
// Hide API tab for non-admins
const originalCondition = tabs.API.condition
tabs.API.condition = function (ctx) {
const { user } = useAuth()
return originalCondition(ctx) && user.roles.includes('admin')
}
Hello! Sorry I do not have any better solution, however, where do you include this code snippet in order to work?
I have a similar problem but with the 'Force Unlock' button, I dont want it to appear for regular users.
I include this in any file that runs on the frontend. It patches the default tab config.
One would could be replacing the existing API Tab Component
And on the custom component, you could copy the existing API tab logic, but add in a user condition
Any solution that would work with Payload 3.0?