You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 056b493
Browse filesBrowse the repository at this point in the historyBrowse files
fix(rbac,webapp): consolidate apiBuilder PAT auth to a single roundtrip
The previous apiBuilder PAT flow ran two PAT lookups per request:
authenticateApiRequestWithPersonalAccessToken first (token validation
+ lastAccessedAt write), then rbac.authenticatePat (cap+floor join).
Two DB roundtrips for what should be one — a regression vs pre-RBAC
main's single findFirst + conditional updateMany.
Option B from the audit:
- plugin contract: `PatAuthResult` now includes `lastAccessedAt: Date | null`
- OSS fallback selects + returns it
- cloud plugin (paired PR): selects + returns it; Drizzle schema mirror
gets the column
webapp apiBuilder now calls rbac.authenticatePat as the sole PAT auth
(empty ctx when no `context`/`authorization` declared — fallback
validates fine), then fires `updateLastAccessedAtIfStale` once with
the plugin-returned timestamp.
`updateLastAccessedAtIfStale` is a new shared helper in
`personalAccessToken.server.ts` that two-layer throttles the write:
JS check elides the SQL entirely when the cached timestamp is fresh
(< 5 min), and the SQL WHERE inside the conditional updateMany is
race-safe for concurrent auths that both decide to fire. The legacy
`authenticatePersonalAccessToken` is refactored to use the same
helper — picks up the JS-side smart-skip for free (was always firing
the updateMany regardless).
Query count (apiBuilder PAT route, fresh cache):
main: 1 findFirst + 1 conditional updateMany = 2
PR before: 1 findFirst + 1 plugin join + 1 updateMany = 3
this commit: 1 plugin auth + 0 (skipped, fresh) = 1 ✓
(stale-cache case still matches main at 2.)
PERMISSIVE_ABILITY local sentinel removed — the plugin always returns
a real ability (permissive in the OSS fallback case, computed in
cloud). Co-located comment in checkAuth() generalised to mention the
permissive ability rather than the removed constant.
Coordinated with the cloud-side change in
triggerdotdev/cloud#763 (rbac-packages branch).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments