Repository navigation
fix(access): resolve manager roles at every locale, not just English - #668
Conversation
`Managers.roles` is localized, but every path that populated the authenticated user resolved it at the default locale — so `req.user.roles` was a flat English array, never the per-locale record the access plugin is written against. The per-locale model was inert at runtime in both directions: every manager's English roles applied in all 19 locales (over-grant), and a manager with no English roles was locked out of the admin entirely (the reported bug). Two reads put it right, and both are needed. `localizedRolesStrategy` wraps Payload's `JWTAuthentication` and re-reads roles at `locale: 'all'`, fixing `req.user`; `afterMe`/`afterRefresh`/`afterLogin` do the same for the three auth responses, which re-read the document themselves and would otherwise overwrite the record the moment the admin client calls `/me`. `hasPermission`'s `locale` is now a `RoleScope`, so each caller states what it means rather than relying on an absent value: a LocaleCode, `'union'` (admin nav visibility, which Payload invokes with no locale — scoping it otherwise empties the sidebar for every non-admin manager), or nothing, which denies. Also: `filterAvailableLocales` no longer force-adds English, ranks locales by role count and never returns empty; `review.ts` threads a locale, which it must or every non-admin manager 403s. Two behaviour changes worth naming. This TIGHTENS access — anyone relying on English roles leaking into other locales loses that on deploy. And `?locale=all` now denies a manager where the flat array used to leak through and grant (200 -> 403); the admin UI never sends it, so this reaches hand-rolled API calls only. Clients are unaffected throughout. Closes #665 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018oiV3fKDoPhKcjhX39LvWp
|
🚅 Deployed to the SahajCloud-pr-668 environment in sahajcloud
1 service not affected by this PR
|
…se roles All three auth-response hooks run INSIDE an open transaction — `login.js` opens at :190, runs `afterLogin` at :263 and commits at :321, and `refresh.js` is the same shape. `hydrateLocalizedRoles` was called with no `req`, so it took a SECOND pool connection while the first was still held. Under concurrency that exhausts the pool and the lane stops making progress rather than failing, which is not a mode any gate reports usefully. Passing the caller's own `req` would fix the connection but reintroduce #609: `createLocalReq` assigns `req.locale` onto the object it is given, so `locale: 'all'` would leak into every later step of the operation. `localeIsolatedReq` is exactly the pair of properties needed — `transactionID` carries by reference so the read joins the existing transaction, while `locale` becomes the copy's own. The auth strategy still passes nothing, correctly: it runs in `executeAuthStrategies`, before any operation, so there is no transaction to join and no caller locale to protect. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018oiV3fKDoPhKcjhX39LvWp
|
Found and fixed a defect of my own while watching CI — pushed The first CI run sat on All three auth-response hooks run inside an open transaction — The fix is
The auth strategy still passes nothing, and that is correct: it runs in ⚠ I have not proven this was the cause of the hang — I cancelled nothing and the original job may simply have been slow. What I can say is that the double-connection-inside-a-transaction was real, was mine, and is the kind of thing that passes every local gate. It passed mine: full integration lane green at 67 files / 1137 tests both before and after, because a 6-fork local run against a fresh Postgres has the headroom to absorb it. Re-validated on 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Correction to my previous comment: there was no hang. The first CI run was healthy. Run 33455977217 started My "over an hour on Keep What still stands unchanged: full gate green on Sorry for the noise on the thread — better a correction than a wrong claim left standing in a PR you are about to review. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Ardnived
left a comment
There was a problem hiding this comment.
Overall it feels like we are adding a ton of additional layers and methods to handle something which should be relatively simple. Take a step back and consider our whole system more holistically, how can we create a system that works in-line with PayloadCMS instead of fighting it?
…o the plugin Addresses the eight review threads on #668. Three of them turned out to be pointing at the same defect, and one of the fixes exposed a second. **`?locale=all` was answered two different ways.** The translation from `req.locale` (a request-supplied string that also carries `'all'`) to `RoleScope` was written out at four call sites, and the fourth disagreed: EventSubmissions' review endpoint resolved `'all'` to `'union'` — a role in ANY locale grants — while collection access, global access and the Frames endpoint denied it. Same request shape, opposite answer, decided by which file you were in. `roleScopeFromLocale` is now the one statement of it, and it denies, matching the three that agreed and the policy the PR body documents. **Writing it once surfaced a privilege escalation the four copies had hidden.** `RoleScope` has one non-locale member, so casting `req.locale` into it lets `?locale=union` NAME the privileged scope: a manager would get their roles from all 19 locales at once — precisely the over-grant #665 exists to remove. The helper therefore returns a scope only for a configured locale. The assertion covering this went red against the first version of the helper, which is how it was found. **The auth wiring moves from Managers.ts to the access plugin.** The strategy and the three auth-response hooks are the plugin's mechanism, not the collection's, so `withLocalizedRoleAuth` now attaches all four and accessPlugin applies it. Managers.ts keeps a comment and no wiring. The predicate is the pair that actually causes the bug — an auth collection whose `roles` field is localized — rather than the slug `managers`, so `Clients` is skipped for a stated reason and a future auth collection is not silently broken. The three hooks stay three: `login`, `/me` and `/refresh-token` each re-read the manager at a single locale, at different moments, and Payload exposes no single point covering them. `localizedRolesAuth.ts` opens with the table of which moment each one closes. `LocalizedRoles` now derives its element type from `Manager['roles']`. Only the per-locale keying is ours. Doing so caught that `Manager['roles']` and `RoleSlug` are NOT the same set — `RoleSlug` includes client roles — so `unionRoles` widened to accept both collections' shapes rather than pretending they are one. Also drops the nine-line comment on the `?locale=all` line, which the helper's docblock now carries in one place instead of at every call site. New: `tests/unit/localizedRolesAuth.spec.ts` covers the attach decision itself. The wiring became a predicate rather than an explicit list, and a predicate that stops matching takes the whole fix offline with nothing in this lane to notice. Every new assertion was made to fail at the site that would really cause it: `'all'`→`'union'` (2 red), predicate ignoring `localized` (1 red), attach replacing rather than appending (1 red). Gates: lint · typecheck · typecheck:tests · 115 files / 1523 unit — all green. The integration lane needs PostgreSQL, which this environment has none of (#663); CI runs it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q9dYn2dB8wsmyCBYURXM6K
# Conflicts: # .claude/rules/access.md # .claude/rules/access.md~HEAD # tests/utils/testData.ts
|
All eight threads answered; six are addressed and resolved, two are open questions for you. Pushed Your review found more than eight nits — three of the threads were pointing at the same defect, and fixing it exposed a second one that all four copies had hidden.
Writing it once surfaced a privilege escalation. The auth wiring moved into the plugin, as you asked, and Two things still with you
What changed, and the gates
The three hooks stayed three, and I could not argue them down: New spec — Every new assertion was made to fail at the site that would really cause it: Gates: lint · typecheck · typecheck:tests · 116 files / 1527 unit — all green. The integration lane needs PostgreSQL and this environment has none (#663), so CI is the first thing to run it; that matters more than usual on an access change, and the access plugin now rewrites every collection's auth config. Also repointed the 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
CI's integration lane caught what my own unit spec could not: the predicate deciding which collections get the localized-roles auth strategy scanned `collection.fields` directly, and `Managers.roles` lives inside a `tabs` field. It never matched, so the strategy and all three auth hooks were attached to nothing and #665's fix was entirely inert on the branch — with lint, typecheck and 1527 unit tests all green. `flattenTopLevelFields` (Payload's own) is the right tool rather than a hand-rolled walk, because it encodes exactly the distinction that matters: `tabs`, `row` and `collapsible` are presentational, so their children are still top-level data (`manager.roles`), while `group` and `array` children sit at a different path and are NOT the field `hydrateLocalizedRoles` selects. A recursive walk that descended into groups would silently hydrate the wrong field. **The spec's fixture was the defect.** It declared `roles` at the top level — easier to write than the real config, and therefore not covering the real config. It now nests `roles` in a `tabs` field exactly as Managers does, with added cases for the flat shape and for a `group`, which must NOT match. Reintroducing the top-level-only scan now turns that spec red (2 failures); before this commit it stayed green through the real failure. Gates: lint · typecheck · typecheck:tests · 117 files / 1534 unit — green. Integration still needs CI (no PostgreSQL here, #663), which is the whole lesson of this commit. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q9dYn2dB8wsmyCBYURXM6K
|
CI went red on my last push and I have fixed it — but the failure is worth reading, because for one commit this PR did nothing at all while every local gate passed. Pushed Moving the wiring into the plugin (your review) meant replacing an explicit list of four hook registrations with a predicate: is this an auth collection whose Green on lint, typecheck, typecheck:tests and 1527 unit tests throughout. My unit spec's fixture was the actual defect. It declared Why
|
| Container | Children's data path | Should match? |
|---|---|---|
tabs, row, collapsible |
manager.roles — presentational only |
yes |
group, array |
manager.group.roles |
no — not the field hydrateLocalizedRoles selects |
A walk that descended into everything would attach the strategy for a group.roles and then hydrate the wrong field, silently. The spec now pins both directions.
On your "is this complicating things" instinct — this is the cost of the predicate, and it is fair to weigh it. What I would say for it: the failure was loud (two integration assertions, naming the exact behaviour), it is now covered in the unit lane, and the alternative — an explicit list in Managers.ts — is what you asked me to remove and what would silently omit the next auth collection. Happy to go back to an explicit registration in the plugin if you would rather have the obviousness; say so and I will.
CI is re-running on 8d200a5. I will not be awake to watch it land — if it is red again, that is on the next run's list.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
@sydevs-bot I've responded to some of your review comments. |
`unionRoles` described the set operation; `rolesForAllLocales` describes the question a caller is entitled to ask. Reviewer's wording, adopted as given. The rename is the second half of making `'union'` unreachable from a request. The first half was `roleScopeFromLocale`, which stopped a request-supplied `?locale=union` from naming the privileged scope. What remains is the helper itself, and its risk is a second caller adopting it by mistake — a name that reads as a generic set union invites that, where one that says "all locales" reads as the deliberate widening it is. No behaviour change: one exported symbol, three call sites, one spec describe block. The docblock stating the single legitimate caller (admin-nav visibility, which Payload invokes with no locale) is unchanged and still the real guard. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01F2BczvDrd7opTwedpZHZ6L
Three admin components call the REST API with a hand-rolled fetch that sends no `?locale=`. Payload resolves such a request at the default locale, and every role gate then evaluates the manager's English roles. Since #668 made roles genuinely per-locale, a manager whose roles live only in another locale is denied on all three surfaces. Confirmed on the reported record: managers/504's `roles` is `{"fr":["path-editor","meditations-editor"]}` — no `en` key at all, so `roles['en'] || []` is empty and `hasPermission` returns false. - FrameEditor/hooks.ts — the locale joins the SWR key, so switching the admin locale refetches for free. - ThumbnailCell — the loader is a module singleton, not a hook, so the locale threads through `load()` and the batch key becomes `relationTo:locale`. Two locales must not share a batch: the response is gated per locale, so merging them would answer one locale's cells from the other's request. - EventSubmissionActions — both URLs carry it. DELETE is not locale-gated today, but consistency costs nothing. Fixed on the client, not the server: the gates are deliberate and documented, and Payload's own fetches already send the locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY
…711) * fix(admin): send the active locale on hand-rolled admin REST fetches Three admin components call the REST API with a hand-rolled fetch that sends no `?locale=`. Payload resolves such a request at the default locale, and every role gate then evaluates the manager's English roles. Since #668 made roles genuinely per-locale, a manager whose roles live only in another locale is denied on all three surfaces. Confirmed on the reported record: managers/504's `roles` is `{"fr":["path-editor","meditations-editor"]}` — no `en` key at all, so `roles['en'] || []` is empty and `hasPermission` returns false. - FrameEditor/hooks.ts — the locale joins the SWR key, so switching the admin locale refetches for free. - ThumbnailCell — the loader is a module singleton, not a hook, so the locale threads through `load()` and the batch key becomes `relationTo:locale`. Two locales must not share a batch: the response is gated per locale, so merging them would answer one locale's cells from the other's request. - EventSubmissionActions — both URLs carry it. DELETE is not locale-gated today, but consistency costs nothing. Fixed on the client, not the server: the gates are deliberate and documented, and Payload's own fetches already send the locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY * test(admin): cover the locale gate over the real REST pipeline The suite was green through the bug because nothing drove Payload's REST pipeline as a manager with roles only in a non-default locale. The handler-level specs build `req` by hand and hardcode `locale: 'en'`, so none of them could see how `req.locale` is derived — which is exactly where #701 lived. - restRequest: `createRestClientAs(env, manager)` logs in any manager, and the caller now takes a method and a JSON body. `createRestClient` keeps its signature and delegates. - frames-by-narrator: three REST cases for a French-only meditations-editor — no `?locale` → 403, `?locale=fr` → 200, `?locale=en` → 403. - event-submissions-review: the same three for an `atlas-manager` on `POST /:id/review`. A sibling file, not a suite in event-submissions.int.spec.ts, because `getPayload` caches per config and a second createTestEnvironment in one file returns the first. - relationshipDocLoader: locale forwarding, per-locale batching, and the default fetcher's URL — the code a comment called "not worth a unit test", where the defect was. Fixture pre-mortem: `testData.createManager` writes a per-locale roles object one locale at a time (verified in tests/utils/testData.ts), so `{ fr: [...] }` really does leave `roles.en` empty — checked against the reported production record, managers/504, whose roles carry no `en` key. `anchorRegion` must be a city or venue, so the review fixture anchors on a city under the managed country (prepareSubmission.ts:101). Every new assertion was confirmed failing first: flipping each fixture's locale to `en` turns all six REST cases red, dropping `locale` from the loader's query object turns the URL case red, and collapsing the batch key to `relationTo` turns the batching case red. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY * docs(access): a hand-rolled admin fetch must send the active locale The rule #701 turned on, stated where each audience reads: the role-scope section of the access rules, and the direct-Payload-access section of the admin UI rules. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY * fix(admin): pin the two unasserted locale call sites, and narrow the rule Adversarial review on #711 raised four threads. All four applied. The written rule in `docs/rules/access.md` was the deliverable #701 chose instead of a shared helper, and it said "on every request" while four hand-rolled admin fetches legitimately do not send a locale. A reader who greps `fetch('/api/` found four counter-examples with nothing to tell them apart, so the rule read as approximate. It now names the condition — the endpoint or collection runs a per-locale `hasPermission` — and tables every call site on each side of it. `docs/rules/admin-ui.md` carried the same overbroad claim and now defers to it. Of the three call sites the fix touches, only the loader's URL was pinned. The two carrying the user-visible half rested on inspection, with the manual browser pass skipped, on a Critical bug live in production. Both now build their URL in a pure module — `framesByNarratorKey` in the FrameEditor's existing `utils.ts`, `eventSubmissionActionUrl` in a new `EventSubmissions/urls.ts` — spec'd in `tests/unit/admin-locale-urls.spec.ts`. This is the reviewer's option 2; option 1 needs a browser this run has no dev server for. Both builders return `null` without a locale, which also settles the third thread: the same falsy `code` was handled three different ways, and the EventSubmissions site interpolated it unguarded. `?locale=undefined` is rewritten to the default locale by `sanitizeLocales`, so that path reproduced the #701 403 silently. It now reports the failure instead. Comment cleanups: the spec docblock's dangling `The` and its argument with the sentence it replaced, and `relationshipDocLoader.ts`'s stale "a single request per relationTo", which the batch-key comment below it contradicted. Every new assertion confirmed failing first, at its own site: dropping the locale from the frames key turns 4 red, dropping the guard from the submission URL turns 1 red. Gate: lint, typecheck, typecheck:tests, test:unit (125 files, 1601 tests). Rebased onto main after #703 merged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Po2VWfKLXuT5TtZRysSDmk --------- Co-authored-by: Claude <[email protected]>
…o the plugin Addresses the eight review threads on #668. Three of them turned out to be pointing at the same defect, and one of the fixes exposed a second. **`?locale=all` was answered two different ways.** The translation from `req.locale` (a request-supplied string that also carries `'all'`) to `RoleScope` was written out at four call sites, and the fourth disagreed: EventSubmissions' review endpoint resolved `'all'` to `'union'` — a role in ANY locale grants — while collection access, global access and the Frames endpoint denied it. Same request shape, opposite answer, decided by which file you were in. `roleScopeFromLocale` is now the one statement of it, and it denies, matching the three that agreed and the policy the PR body documents. **Writing it once surfaced a privilege escalation the four copies had hidden.** `RoleScope` has one non-locale member, so casting `req.locale` into it lets `?locale=union` NAME the privileged scope: a manager would get their roles from all 19 locales at once — precisely the over-grant #665 exists to remove. The helper therefore returns a scope only for a configured locale. The assertion covering this went red against the first version of the helper, which is how it was found. **The auth wiring moves from Managers.ts to the access plugin.** The strategy and the three auth-response hooks are the plugin's mechanism, not the collection's, so `withLocalizedRoleAuth` now attaches all four and accessPlugin applies it. Managers.ts keeps a comment and no wiring. The predicate is the pair that actually causes the bug — an auth collection whose `roles` field is localized — rather than the slug `managers`, so `Clients` is skipped for a stated reason and a future auth collection is not silently broken. The three hooks stay three: `login`, `/me` and `/refresh-token` each re-read the manager at a single locale, at different moments, and Payload exposes no single point covering them. `localizedRolesAuth.ts` opens with the table of which moment each one closes. `LocalizedRoles` now derives its element type from `Manager['roles']`. Only the per-locale keying is ours. Doing so caught that `Manager['roles']` and `RoleSlug` are NOT the same set — `RoleSlug` includes client roles — so `unionRoles` widened to accept both collections' shapes rather than pretending they are one. Also drops the nine-line comment on the `?locale=all` line, which the helper's docblock now carries in one place instead of at every call site. New: `tests/unit/localizedRolesAuth.spec.ts` covers the attach decision itself. The wiring became a predicate rather than an explicit list, and a predicate that stops matching takes the whole fix offline with nothing in this lane to notice. Every new assertion was made to fail at the site that would really cause it: `'all'`→`'union'` (2 red), predicate ignoring `localized` (1 red), attach replacing rather than appending (1 red). Gates: lint · typecheck · typecheck:tests · 115 files / 1523 unit — all green. The integration lane needs PostgreSQL, which this environment has none of (#663); CI runs it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q9dYn2dB8wsmyCBYURXM6K
Three admin components call the REST API with a hand-rolled fetch that sends no `?locale=`. Payload resolves such a request at the default locale, and every role gate then evaluates the manager's English roles. Since #668 made roles genuinely per-locale, a manager whose roles live only in another locale is denied on all three surfaces. Confirmed on the reported record: managers/504's `roles` is `{"fr":["path-editor","meditations-editor"]}` — no `en` key at all, so `roles['en'] || []` is empty and `hasPermission` returns false. - FrameEditor/hooks.ts — the locale joins the SWR key, so switching the admin locale refetches for free. - ThumbnailCell — the loader is a module singleton, not a hook, so the locale threads through `load()` and the batch key becomes `relationTo:locale`. Two locales must not share a batch: the response is gated per locale, so merging them would answer one locale's cells from the other's request. - EventSubmissionActions — both URLs carry it. DELETE is not locale-gated today, but consistency costs nothing. Fixed on the client, not the server: the gates are deliberate and documented, and Payload's own fetches already send the locale. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012noYdvt78W3aLKqJpDpEQY
Summary
A manager whose roles are assigned in a non-default locale could not use the admin at all. The cause was one missing read:
Managers.rolesislocalized, and every path that populated the authenticated user resolved it at the default locale — soreq.user.roleswas a flat English array, never the per-locale recordsrc/plugins/accessis written against.The per-locale model was therefore inert at runtime, in both directions:
⚠ This tightens access. Anyone relying on their English roles leaking into other locales loses that the moment it deploys. Audit
Managersrole assignments before deploying, per the ticket's deployment note.Where the mechanism lives
src/plugins/access/localizedRolesAuth.ts— one file, one export (withLocalizedRoleAuth).accessPluginattaches it;Managers.tsconfigures none of it and carries only a four-line comment saying where it lives.Attachment keys on the condition, not the slug: an auth collection whose
rolesfield islocalized. SoClientsis skipped for a stated reason (itsrolesis flat), and a future auth collection with localized roles is covered on arrival rather than broken silently.It is four reads rather than one because Payload re-loads the manager at four moments, each at a single locale:
req.user.rolesis flat — every server-side access check is wrongafterLoginafterMeAuthProvidercalls/meon mount and overwrites the strategy — right projects on first paint, then "No Projects Available"afterRefreshRegistration order makes the strategy safe: custom strategies are collected first and
local-jwtis appended last, andexecuteAuthStrategiesreturns on the first strategy yielding a user — so this runs in front of the default rather than replacing it.hasPermission'slocaleis aRoleScope, and requests cannot name the privileged oneLocaleCode'union'undefined?locale=all, and any locale not inLOCALESEvery request-to-scope translation goes through
roleScopeFromLocale, which validates againstLOCALESrather than casting. That replaced four hand-written copies that had already drifted — and the fourth (EventSubmissions/review.ts) answered?locale=allwith'union'where the other three denied it.Writing it once surfaced a privilege escalation none of the four copies showed.
req.localeis a request-supplied string andRoleScopehas a non-locale member, so a plain cast let?locale=unionname the privileged scope and hand a manager their roles from all 19 locales — exactly the over-grant #665 exists to remove. Found because the assertion written for it went red against the first implementation, which did cast.'union'survives as something a call site opts into, never something a caller can be talked into. Payload'shidden?: ((args: { user: ClientUser }) => boolean)signature (types.d.ts:414) offers no locale at all, andgetVisibleEntitiestreats a throw as hidden — so scoping nav visibility otherwise empties the sidebar of every collection and global for every non-admin manager.Two behaviour changes worth your eye
1.
?locale=allnow denies a manager where it used to grant (200 → 403). This is the ticket's open question 1, implemented as the apparent original intent: a request for every locale at once names no locale to evaluate roles in, and the previous grant was the flat array leaking through — not a decision. The admin UI never sends it (publish-all-locales is a body flag, not a query locale), so it reaches hand-rolled API calls only. Clients are unaffected throughout, sinceClients.rolesis not localized.2. The locale dropdown no longer force-adds English, lists only locales the manager holds a role in, and orders them most-roles-first. That first entry is also where Payload lands them, so the ordering is real behaviour rather than cosmetics. A manager with roles in no locale still gets English and still sees the banner.
Test results
lint✓ ·typecheck✓ ·typecheck:tests✓Three new unit specs (
localizedRoles.spec.ts,localizedRoleScope.spec.ts,localizedRolesAuth.spec.ts), plus two integration cases that authenticate for real throughpayload.auth— the mock-only gap that let this bug live.Every new assertion was made to fail before being kept — including one that revealed a guard with no coverage at all
Per
.claude/rules/tests.md, each defect was reintroduced at the site that would really cause it:filterAvailableLocalesLOCALESorder)extractRolesresolves across all locales regardless of scopelocalizedlocale: 'union'fromcreateHiddenThat last row is the useful one. The union scope in
createHiddenis what keeps the admin sidebar from emptying for every non-admin manager, and removing it broke nothing in the suite.tests/unit/localizedRoleScope.spec.tsexists because of that, and it now goes red on exactly that removal.Library behaviours read from
node_modules/rather than assumedEach of these would produce a silent wrong answer if taken on trust:
local-jwtpasses no locale.auth/strategies/jwt.js:67-71callspayload.findByID({ id, collection, depth }), andcreateLocalReqthen setsreq.locale = localization.defaultLocale. This is the root cause, confirmed in source.JWTAuthenticationis exported frompayload(index.d.ts:509), so the strategy wraps it rather than reimplementing the session check, the_verifiedgate and the autoLogin fallbacks.local-jwt, which is appended last (index.js:437-446). Adding one does not disable the default.executeAuthStrategiesswallows thrown errors (lines 21-26) and falls through to the next strategy. So a hydration failure that threw would silently restore the flat, over-granting shape — the strategy therefore catches and returns an empty role record instead. Fails closed and visibly ("No Projects Available") rather than open and silently.afterLoginruns BEFORE the field-levelafterReadpass inlogin.js, which resolves localized fields at the request locale. That ordering is noted in the hook's docblock; the load-bearing hook isafterMe, and that is the one the integration test asserts.hiddenreceives{ user }and nothing else —payload/dist/collections/config/types.d.ts:414. Noreq, nolocale, no way to obtain one.The test-suite assertions that certified the bug, and what changed
tests/int/role-based-access.int.spec.tsasserted against flat arrays with no locale at nine sites — including insidedescribe('Localized Manager Roles'). Those passed only because of theArray.isArrayshort-circuit, so the suite did not merely miss this bug, it encoded it as the expected contract. They are rewritten to the per-locale shape with an explicit locale, not extended.testData.createManageraccepted a{ en, cs }roles object and wrote onlyroles.en, so the manager in the bug report — roles in a non-English locale only — was unconstructible. It now writes every locale it is given, creating at the first and updating for the rest, since a single create only stores the locale it was created at._verified: trueis set explicitly on the managers in the new login tests:Managersconfiguresauth.verify, andcreatedoes not imply it the wayfirst-registerdoes.Review rounds — what your feedback changed
Round 1 (8 threads, all resolved). The largest change was structural, and it was yours: the strategy and the three hooks moved out of
src/collections/Managers/into the access plugin as one file, and the plugin now attaches them itself. Two files → one, six exports → one,Managers.ts−18 lines.Two threads produced defects rather than tidying:
req.localetranslation exposed the?locale=unionescalation described above.LocalizedRolesfromManager['roles']rather than hand-writing it revealed the hand-written type was wider than the truth —RoleSlugincludes client roles likewemeditate-web-client, which a manager's record should never accept.A defect of mine reached CI in this round. Rewriting the wiring as a predicate left it scanning only top-level fields, and
Managers.rolessits inside atabsfield — so the entire fix was inert on the branch while lint, typecheck and 1527 unit tests passed. Two integration assertions caught it. Fixed in8d200a5using Payload's ownflattenTopLevelFields, which encodes the distinction that matters:tabs/row/collapsiblechildren are stillmanager.roles, whilegroup/arraychildren sit at a different data path and must not match. The spec now pins both directions. The cause was my own unit fixture declaringrolesat the top level because that was easier to write than the real config.Round 2 (2 threads, both resolved).
unionRoles→rolesForAllLocales(eae73ce), your wording.TypedAuthUsercleanup is filed as NarrowTypedAuthUserontoManager/Client— and decide where the admin-view''is handled #671 rather than bolted on here. A scan for it found this codebase is otherwise clean —src/types/tags.tsandframes.tsalready derive from the generated types — so NarrowTypedAuthUserontoManager/Client— and decide where the admin-view''is handled #671 is a bounded ticket whose real work is one member: narrowingcurrentProjectmeans every consumer must handle the admin-view'', across the whole access plugin.What I did NOT verify
Steps 4–8 of the ticket's verification checklist require driving the admin UI in a browser against a seeded database — the landing redirect settling on
?locale=fr, the header label agreeing withreq.locale, and the banner not reappearing after/meand the refresh timer fire. I could not run those, and the redirect in particular is Payload's own behaviour that this PR activates by dropping forced-English rather than implements. Worth a manual pass before merge.Closes #665
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01F2BczvDrd7opTwedpZHZ6L