Repository navigation
fix: browse and search routes add request details only for a checked account - #489
Merged
Merged
Conversation
Popular, new releases, category and audiobook search take the caller from a new optional-auth helper, getOptionalAuthUser, which runs the same account checks as requireAuth and returns null instead of a 401. Request details and ignore flags are added only for a checked account; any other caller gets the same books without them. Signed-in responses are unchanged. The unused getCurrentUser, getCurrentUserAsync and isAdmin helpers are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
What changed
getOptionalAuthUsernext torequireAuth(src/lib/middleware/auth.ts). It runs the same account checks asrequireAuthand takes the role from the account row. It returns the caller, ornull; it never answers 401. Both helpers share one access-token check (checkAccessToken), so the refusal rules live in one place. An API token counts only on an endpoint on the API-token allowlist, as withrequireAuth.getOptionalAuthUser:src/app/api/audiobooks/popular/route.ts(GET)src/app/api/audiobooks/new-releases/route.ts(GET)src/app/api/audiobooks/category/[categoryId]/route.ts(GET)src/app/api/audiobooks/search/route.ts(GET)enrichAudiobooksWithMatches(src/lib/utils/audiobook-matcher.ts) adds request details (isRequested,requestStatus,requestId,requestedByUserId,requestedByUsername) only when it gets a caller id, and skips the request lookup without one. Without a checked caller every book reportsisRequested: falseandnullrequest fields, andisIgnored: false. Availability and reported-issue flags are unchanged for everyone.getCurrentUser,getCurrentUserAsyncandisAdminfromsrc/lib/middleware/auth.ts. They have no callers left.documentation/backend/services/auth.md(middleware list and one Fixed Issues line) anddocumentation/backend/services/api-tokens.md(search route and helper names).Why
These routes now check the account before adding request details, like the other signed-in routes.
Evidence
tests/api/discovery-routes.request-details.test.tsruns the real auth middleware and the real matcher against all four handlers. On each route, the following get 200 with the same books and no request details: a deleted account, a missing account row, a pending account, a rejected account, a token issued before the sessions were revoked, no token, and an unverifiable token. A live account gets exactly the body it got before, requester names included. On search, an API token gets the same body as before. An API token whose owner was deleted gets no request details, and so does an API token on the three routes that are not on the allowlist.tests/utils/audiobook-matcher.test.ts: without a caller id, no request details and no request lookup.main(5cf6f11) with these test files: 33 failed, 10 passed, all on an assertion. The 10 that pass onmainare the 4 live-account cases, the API-token search case and the 5 existing matcher cases, which confirms the signed-in bodies are unchanged. On this branch: 43/43 pass.tests/middleware/auth.middleware.test.ts,session-account-status.test.tsandsession-current-role.test.tsnow testgetOptionalAuthUserin place of the removed helpers (JWT account row, current role, allowlist, API-token account status).tests/api/audiobooks-browse.routes.test.tsmocks the new helper.authenticatedFetcherinsideProtectedRoute, after the session has loaded, so a signed-in user sees the same badges and requester names as before.Checks
vitest relatedon the 6 source files plus the 7 test files): PASS, 123 files, 1583/1583tsc --noEmitclean; ESLint on the 13 touched files: 43 findings onmainand 43 on this branch, same rules per file, none new)npm run e2e -- --specs smoke, imagermab-e2e/t106:83c4ae8, same source as the head commit): PASS, 1/1Risk and rollback
requireAuthdoes. A request with no checked caller skips the request lookup.Release note
🤖 Generated with Claude Code