#5 feat: Added auth header to API transport - #5
Draft
Chriztiaan wants to merge 1 commit into
Draft
Chriztiaan wants to merge 1 commit into
Chriztiaan wants to merge 1 commit into
Conversation
This was referenced Sep 17, 2026
Merged
ckritzinger
pushed a commit
to ckritzinger/powersync-temp-write-api
that referenced
this pull request
Sep 18, 2026
ckritzinger
pushed a commit
to ckritzinger/powersync-temp-write-api
that referenced
this pull request
Sep 18, 2026
Three things the merge of powersync-ja#5 and powersync-ja#7 got textually clean but semantically wrong, plus the regeneration the spec fix forces. - openapi.yaml: /api/data/batch now declares `security: bearerAuth` and a 401 response. powersync-ja#5 mounts requireAuth at router.use('/data', ...), which already covers the sub-path, so the spec was contradicting the implementation. - OpenAPITransport: 401 recovery moves from postTransaction into an onResponse middleware. It was written per-method in powersync-ja#5, so the batch endpoint powersync-ja#7 added threw on 401 without ever clearing the cached token — wedging the batch path until a reload. The bearer header was already attached centrally; the rejection now is too, so endpoints added later inherit both. - data.ts: the /batch handler logs the verified writer, matching what powersync-ja#5 does for single-transaction writes. Regenerated types follow from the spec change.
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 /api/datapreviously accepted any request. This PR gates it behind a bearer JWT: the backend verifies the token on every write, and the frontend attaches one to every upload. The verification logic sits behind a single pluggable interface so adopters can swap the demo verifier for a real identity provider (Supabase, Clerk, etc.) by editing one file.How it works
The demo keeps its one-token shape: the client already fetches a PowerSync JWT from
/api/auth/tokeninfetchCredentials()for sync. Writes now reuse that same token as the bearer credential, and the backend verifies it against its own public key (the same key it signs with, exposed via a newgetPublicJwk()helper).Docs
auth-verifiers.md— adopter guide for swapping the verifier to Supabase or Clerk: worked verifier snippets, env vars, frontendgetToken()wiring, sync-token options, and a verification checklist.AI disclosure
This PR was created with the help of Claude Code. Help constitutes assistance in research, planning, and rough outline of implementation. Beyond having a hand in the implementation, I have also manually tested this work.