The best way to build a modern backend + admin UI. No black magic, all TypeScript, and fully open-source, Payload is both an app framework and a headless CMS.
The access control functions (i.e. the AccessArgs type) include a req object in the request, which includes the locale variable.
In my case, I want to restrict access to some locales for different users, i.e. be able to only allow a user to access a certain locale (f.ex. only allow the user to edit documents on the 'is' locale, but not the ones on 'en').
My attempt at this was to have the access function in the following format:
Link to reproduction
No response
Describe the Bug
The access control functions (i.e. the AccessArgs type) include a
req
object in the request, which includes the locale variable.In my case, I want to restrict access to some locales for different users, i.e. be able to only allow a user to access a certain locale (f.ex. only allow the user to edit documents on the 'is' locale, but not the ones on 'en').
My attempt at this was to have the access function in the following format:
However, when I load the dashboard on the 'is' locale, the function is called with
req.locale = 'en'
, while it naturally should be 'is'.Additionally, the access functions do not get called when the locale state updates, i.e. when I change the locale in the dashboard.
To Reproduce
I wrote a small
create-payload-app
repo that recreates the bug: https://github.com/karirogg/payload-access-control-locale-bug.In short, I added this collection to the blank template:
and added the following to the
payload.config.ts
:When I refresh the page on the 'is' part of the dashboard, this function logs the locale being 'en'.
Payload Version
2.22.0
Adapters and Plugins
bundler-webpack, db-mongodb, plugin-cloud, richtext-slate