Repository navigation
fix(api): return 401 for invalid or revoked API tokens - #1314
Merged
slothful-vassal merged 3 commits intoOct 4, 2026
Merged
slothful-vassal merged 3 commits into
slothful-vassal merged 3 commits into
Conversation
Contributor
|
Thanks a lot for the fix and the thorough tests! I pushed one small follow-up commit on top: /auth/token now answers 401 for unknown/revoked and expired tokens, and the hook checks e.status === 401 instead of matching the error message. Two reasons:
A missing endpoint (404) or any other backend failure still results in a 500, as before. I extended your hook tests with the expired case and added a Go test for the handler's status codes. The bearer prefix/case handling from the issue's optional point is left for a separate change. |
slothful-vassal
previously approved these changes
Oct 4, 2026
slothful-vassal
approved these changes
Oct 4, 2026
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.
Fixes #1309.
Unknown or revoked Wanderer API tokens currently turn PocketBase's credential rejection into HTTP 500. Clients such as Gadgetbridge then see a server failure instead of an authentication failure.
Return JSON HTTP 401 with
message: "invalid_token"andWWW-Authenticate: Bearer error="invalid_token"for that specific rejection. Unrelated backend 400/404/500 responses and connection failures retain their server-error handling. This change is limited to invalid/revoked Wanderer API tokens.Tested on Linux with Node 24 and the locked dependencies:
npm run test:unit -- --run: 278 passed, 11 existing engine tests skipped by their environment guard; nine new hook cases use the real PocketBase SDK and loopback HTTP.npm run check: zero errors or warnings.npm run build: successful.AuthTokenhandler: unknown and actually revoked tokens return 500 on the unpatcheddevbase and JSON 401 on this patch. Valid-token and cookie authentication, public access, missing-token upload rejection, backend 500, generic backend 404, and connection failure were also checked.To reproduce, request
/api/v1/api-tokenwithAuthorization: Bearer wanderer_key_bogus. The response is now JSON 401 rather than 500.