Skip to content

fix(office): the geographic settings screen reads through the API, not PostgREST - #863

Merged
thinkclay merged 3 commits into
mainfrom
fix/856-office-settings
Sep 22, 2026
Merged

thinkclay merged 3 commits into
mainfrom
fix/856-office-settings

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #856. Found by the release-1 route sweep (#852). Pairs with Scaffald/sdk#31.

The problem

core.system_config has RLS off and grants only postgres and service_role, so the screen's direct supabase.schema('core') read answered 42501 insufficient privilege on every load. Combined with an effect that showed a toast and depended on the toast hook, the failure re-triggered itself: ~35,000 requests per visit, never settling. #855 fixed the unbounded half; this removes the failure itself.

Why an endpoint rather than a grant

The obvious one-line fix is GRANT SELECT ON core.system_config TO authenticated. That is a wider door than the screen needs. The table holds platform limits — storage caps, photo limits, the verification flag, the site-overlap threshold — that only the office role may read or change, and with RLS off a grant means every logged-in user can read all of it. Every other office screen reads privileged data through the service role behind requireRole, and this one now does the same.

GET  /v1/office/settings/geographic
PUT  /v1/office/settings/geographic

Two details worth naming:

  • A missing row is not an error. The setting has simply never been changed from its default; answering 404 would put the screen into its error state on a healthy install.
  • value is jsonb and has been written both as a number (this handler) and as a quoted string (the old screen's numValue.toString()), so the read accepts either.

Client

useGeographicSettings / useUpdateGeographicSettings replace the direct query. A failed read now renders once with a retry button instead of raising a toast from inside the effect that fetched.

Verification

  • nx run scf-core:typecheck, the app's tsc --noEmit, and the SDK's build and typecheck all clean. pnpm prepush clean.
  • tests/routers/office-settings-rest.test.ts — 4 tests written, not run here: an office caller reads the value, an anonymous caller is refused, an out-of-range threshold is rejected, and a saved value reads back (restoring the original afterwards). The local edge runtime serves the main checkout rather than this worktree, so these run in the normal api-test flow.

Needs the submodule pointer re-pointed at the squashed commit once Scaffald/sdk#31 merges.

One thing found on the way

pnpm prepush failed with teams.router.ts(824,39): error TS2589: Type instantiation is excessively deep — in a file this branch does not touch. It reproduced with my route removed and the SDK pointer back at main, so it looked like a broken build on main, and the repo already has a @ts-expect-error precedent for exactly that message. It was a stale packages/supabase/tsconfig.tsbuildinfo: deleting it (gitignored) made the build pass with no code change. Worth knowing before anyone annotates working code to get past it.

🤖 Generated with Claude Code

…t PostgREST

`core.system_config` has RLS off and grants nothing to `authenticated`, so
the screen's direct `supabase.schema('core')` read answered 42501 on every
load. The grant is deliberately not widened: the table holds platform
limits — storage caps, photo limits, the site-overlap threshold — that
only the office role may read or change, and SELECT for every logged-in
user is a far wider door than one admin form needs. Service role behind a
role-checked endpoint is how every other office screen reads privileged
data.

  GET  /v1/office/settings/geographic
  PUT  /v1/office/settings/geographic

A missing row is not an error: the setting has simply never been changed
from its default, and answering 404 would put the screen into its error
state on a healthy install. `value` is jsonb and has been written both as
a number and as a quoted string, so the handler reads either.

On the client, `useGeographicSettings` / `useUpdateGeographicSettings`
replace the direct query. The failed read now renders once, with a retry,
instead of raising a toast from inside the effect that fetched — which is
what made the failure re-trigger itself (#852 fixed the unbounded half;
this removes the failure).

Needs the pointer re-pointed at the squashed commit once Scaffald/sdk#31
merges.

Closes #856

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


thinkclay and others added 2 commits September 22, 2026 15:42
# Conflicts:
#	apps/scaffald/app/(admin)/office/settings/geographic.tsx
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay
thinkclay merged commit 7ccfe2b into main Sep 22, 2026
14 checks passed
@thinkclay
thinkclay deleted the fix/856-office-settings branch September 22, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(db): core.system_config grants nothing to authenticated, so the geographic settings screen 403s on every read

1 participant