Repository navigation
fix(office): the geographic settings screen reads through the API, not PostgREST - #863
Merged
Merged
Conversation
…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]>
Contributor
📊 Performance Benchmark Results |
11 tasks
Scaffald/sdk#31 merged as f29eb76. Co-Authored-By: Claude Opus 5 <[email protected]>
# Conflicts: # apps/scaffald/app/(admin)/office/settings/geographic.tsx
Contributor
📊 Performance Benchmark Results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #856. Found by the release-1 route sweep (#852). Pairs with Scaffald/sdk#31.
The problem
core.system_confighas RLS off and grants onlypostgresandservice_role, so the screen's directsupabase.schema('core')read answered42501 insufficient privilegeon 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 behindrequireRole, and this one now does the same.Two details worth naming:
valueis jsonb and has been written both as a number (this handler) and as a quoted string (the old screen'snumValue.toString()), so the read accepts either.Client
useGeographicSettings/useUpdateGeographicSettingsreplace 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'stsc --noEmit, and the SDK's build and typecheck all clean.pnpm prepushclean.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 prepushfailed withteams.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 onmain, and the repo already has a@ts-expect-errorprecedent for exactly that message. It was a stalepackages/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