#hide "API" tab for some users

9 messages · Page 1 of 1 (latest)

dense quarry
#

How could I hide the "API" tab only for some users (non-admins)? I tried setting hideAPIURL to a function but that doesn't seem to work.

rain rockBOT
dense quarry
#

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')
}
quick trench
dense quarry
#

I include this in any file that runs on the frontend. It patches the default tab config.

coarse escarp
#

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

heady canopy
#

Any solution that would work with Payload 3.0?