Respecting Access Control with Local API Operations
In Payload, local API operations override access control by default. This means that operations will run without checking if the current user has permission to perform the action. This is useful in certain scenarios where access control is not necessary, but it is important to be aware of when to enforce it for security reasons.
Default Behavior: Access Control Skipped
By default, local API operations skip access control. This allows operations to execute without the system checking if the current user has appropriate permissions. This might be helpful in admin or server-side scripts where the user context is not required to perform the operation.
For example:
Respecting Access Control
If you want to respect access control and ensure that the operation is performed only if the user has appropriate permissions, you need to explicitly pass the user
object and set the overrideAccess
option to false
.
overrideAccess: false
: This ensures that access control is not skipped and the operation respects the current user's permissions.user
: Pass the authenticated user context to the operation. This ensures the system checks whether the user has the right permissions to perform the action.
This example will only allow the document to be created if the user
we passed has the appropriate access control permissions.