fix(api): stop a failed ownership check from masquerading as 404 - #46
Merged
Merged
Conversation
ownsProject/ownsFigure discarded the Supabase error from their select() calls and returned false whenever data came back null — which is also what happens on a real query failure (RLS misconfig, DB outage). Every route's authorization check then reported "Not found" instead of surfacing a server error, same bug class as #40 but one layer down in the shared ownership helper, affecting every POST/PATCH/DELETE (and several GETs) across surfaces, compositions, and figures. ownsProject/ownsFigure now return { owns, error } so callers can tell a real failure (500) apart from "caller doesn't own this" (404). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
ownsProject/ownsFigureinapp/src/lib/api/ownership.tsdiscarded the Supabaseerrorfrom theirselect()calls, so a real query failure (RLS misconfig, DB outage, transient network error) looked identical to "caller doesn't own this row" — both leavedatanull.Changes
ownsProject/ownsFigurenow return{ owns: boolean; error: string | null }instead of a bareboolean.ownership.errorfirst and return 500 before falling through to the 404 "not owned" branch.ownership.test.tsto match the new return shape and added two new tests asserting a query failure surfaces via.errorrather than being silently reported asowns: falsewith no signal.Test plan
npx tsc --noEmit— cleannpm run lint— 0 errors (8 pre-existing warnings, unrelated to this change)npx vitest run— 98 pass, 0 fail (includes 2 new tests for the fixed error path)Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com