Skip to content

Per-user API keys: apiKey on BoolUser + auth.rotateApiKey() - #5

Merged
max-bader merged 1 commit into
mainfrom
claude/per-user-api-keys
Jul 16, 2026
Merged

max-bader merged 1 commit into
mainfrom
claude/per-user-api-keys

Conversation

@max-bader

Copy link
Copy Markdown
Contributor

The gateway's /users/me now lazily mints + returns a personal api_key for the signed-in end user (Base44 convention): external callers send it as the api_key header and act exactly as that user — same per-user RLS scoping as in the app.

SDK side is deliberately thin (getUser() passes the server user object through):

  • BoolUser.apiKey?: string — typed access to the key.
  • auth.rotateApiKey() — POSTs /users/api-key/rotate; the old key stops working immediately. Surfaces the 503 (keys not configured on the deployment) as an error.

Tests: 3 new (passthrough, rotate happy path, 503 handling) — 55/55 green, build clean.

Pairs with the bool-side gateway change (accepts api_key → stamps sub → existing RLS). Publish as 0.2.0-next.7 once that lands.

🤖 Generated with Claude Code

The gateway's /users/me now lazily mints and returns a personal api_key
for the signed-in end user (Base44 convention): external callers send it
as the `api_key` header and act exactly as that user, same RLS scoping
as in the app.

SDK side is thin because getUser() passes the server user object
through: add the `apiKey?: string` field to BoolUser (typed access to
(await auth.getUser()).data.user.apiKey) and an auth.rotateApiKey()
helper that POSTs /users/api-key/rotate (old key dies immediately).

Pairs with the bool-side gateway change (api_key header → sub → RLS).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@max-bader
max-bader marked this pull request as ready for review July 16, 2026 19:05
@max-bader
max-bader merged commit 7593e46 into main Jul 16, 2026
3 checks passed
@max-bader
max-bader deleted the claude/per-user-api-keys branch July 16, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant