fix(web): acquire bearer token in useEntityForm before create/update#82
Merged
Merged
Conversation
The registry create + edit forms on the spec-006 polymorphic surface
were sending POST /api/registry and PUT /api/registry/{id} without an
Authorization header, getting a 401 back. Root cause: useEntityForm
accepted an apiOptions prop carrying the access token, but neither
namespace-form.tsx nor child-entity-form.tsx ever passed it. With no
explicit accessToken, the registry api client built headers without
Bearer auth, and the api endpoint group's RequireAuthorization() gate
rejected the request before it reached the handler.
Fix: call useAcquireToken() inside the hook and stamp the token into a
resolvedApiOptions wrapper before invoking createEntity / updateEntity.
External callers can still pass apiOptions with their own accessToken
to override (the explicit-token path the api-client comment documents).
No backend change. No new dependency. Same pattern as the spec-008
namespace forms (use-acquire-token + apiOptions composition).
Co-Authored-By: Claude Opus 4.7 (1M context) <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
POST/PUT against
/api/registryfrom the spec-006 registry forms (namespace create, queue/topic/sub/rule create + edit) returned 401 with no Bearer header on the request.useEntityFormaccepted anapiOptionsprop carrying the access token, but neithernamespace-form.tsxnorchild-entity-form.tsxever passed it. The registry api client builds headers withoutAuthorization: Bearerwhenoptions.accessTokenis undefined, so the backend'sRequireAuthorization()gate (FR-037 AuthN-only) returned 401 before any handler ran.Same pattern as the spec-008 namespace forms which already use
useAcquireToken()internally — this fix brings the spec-006 form hook up to the same standard.Fix
Inside
useEntityForm:External callers can still pass
apiOptions.accessTokento override (the explicit-token path is documented inweb/lib/api-client.ts).Test plan
pnpm typecheckclean/registry, submit, expect 201 (not 401)Risk
None — additive token acquisition inside the existing submit path, no schema change, no backend change.
🤖 Generated with Claude Code