feat: Added auth header to API transport#5
Draft
Chriztiaan wants to merge 1 commit into
Draft
Conversation
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.