create, read, update, delete, etc. Access Control functions are executed before any changes are made and before any operations are completed. This allows you to determine if the user has the necessary permissions before fulfilling the request.
There are many use cases for Access Control, including:
- Allowing anyone
readaccess to all posts - Only allowing public access to posts where a
statusfield is equal topublished - Giving only users with a
rolefield equal toadminthe ability to delete posts - Allowing anyone to submit contact forms, but only logged in users to
read,updateordeletethem - Restricting a user to only be able to see their own orders, but no-one else’s
- Allowing users that belong to a certain organization to access only that organization’s resources
Default Access Control
FrogBot provides default Access Control so that your data is secured behind Authentication without additional configuration. To do this, FrogBot sets a default function that checks that a user is present on the request and that the user belongs to the collection used to access the Admin Panel (config.admin.user). You can override this default behavior by defining your own Access Control functions as needed.
This means that adding a second Authentication-enabled collection does not automatically grant its users access to everything. Users from collections other than config.admin.user are denied by default unless you provide your own Access Control functions.
Here is the default Access Control that FrogBot provides:
The Access Operation
The Admin Panel responds dynamically to your changes to Access Control. For example, if you restrict editingExampleCollection to only users that feature an “admin” role, FrogBot will hide that Collection from the Admin Panel entirely. This is super powerful and allows you to control who can do what within your Admin Panel using the same functions that secure your APIs.
To accomplish this, FrogBot exposes the Access Operation. Upon login, FrogBot executes each Access Control function across all Collections and Fields and returns a response that reflects what the authenticated user can do within your application.
If you use id, data, siblingData, blockData and doc within your access control functions, make sure to check that they are defined first. If they are not, then you can assume that your Access Control is being executed via the Access Operation to determine solely what the user can do within the Admin Panel.
Locale Specific Access Control
To implement locale-specific access control, you can use thereq.locale argument in your access control functions. This argument allows you to evaluate the current locale of the request and determine access permissions accordingly.
Here is an example: