Skip to content

agent: @U0AJM7X8FBR CLI - add the ability for users to create an account, upgra#326

Open
sweetmantech wants to merge 1 commit intotestfrom
agent/-u0ajm7x8fbr-cli---add-the-abi-1774105595692
Open

agent: @U0AJM7X8FBR CLI - add the ability for users to create an account, upgra#326
sweetmantech wants to merge 1 commit intotestfrom
agent/-u0ajm7x8fbr-cli---add-the-abi-1774105595692

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

@sweetmantech sweetmantech commented Mar 21, 2026

Automated PR from coding agent.

Prompt: @U0AJM7X8FBR CLI - add the ability for users to create an account, upgrade to pro, and create and delete their api keys

Summary by CodeRabbit

  • New Features
    • Expanded authentication support for API key management. Users can now authenticate API key operations (create, retrieve, and delete) using both API key credentials and Bearer tokens. This provides greater flexibility when integrating API key management across different applications and deployment scenarios.

Replace getAuthenticatedAccountId (Bearer-only) with validateAuthContext
in GET/POST/DELETE /api/keys handlers so CLI users authenticating via
x-api-key header can manage their API keys.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Mar 21, 2026 3:09pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 21, 2026

📝 Walkthrough

Walkthrough

Three API key handlers (createApiKeyHandler, deleteApiKeyHandler, and getApiKeysHandler) were refactored to use validateAuthContext() instead of getAuthenticatedAccountId() for authentication. The new authentication method supports both x-api-key and Authorization: Bearer credentials. Core business logic remains unchanged.

Changes

Cohort / File(s) Summary
API Key Handler Authentication Refactor
lib/keys/createApiKeyHandler.ts, lib/keys/deleteApiKeyHandler.ts, lib/keys/getApiKeysHandler.ts
Replaced getAuthenticatedAccountId() with validateAuthContext() to support both x-api-key and Bearer token authentication. The accountId is now destructured from authResult.accountId. All downstream business logic (validation, authorization checks, and operations) remains unchanged. Documentation updated to reflect dual authentication support.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🔑 Three guardians stand tall, with expanded sight,
Now welcoming both bearer tokens and keys bright,
validateAuthContext brings unified grace,
Where credentials diverse find their rightful place. 🔐

🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Solid & Clean Code ⚠️ Warning PR violates DRY principle by duplicating identical 5-line authentication validation block across three handlers without abstraction. Extract authentication handling into reusable helper function to eliminate duplication and ensure single-point maintenance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/-u0ajm7x8fbr-cli---add-the-abi-1774105595692

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/keys/createApiKeyHandler.ts (1)

19-23: Consider extracting the repeated auth gate into a shared utility (DRY).

The same validateAuthContext + instanceof NextResponse + { accountId } extraction block now exists in all three key handlers; a small helper would reduce repetition and keep future auth changes centralized.

As per coding guidelines: **/*.{ts,tsx}: Extract shared logic into reusable utilities following Don't Repeat Yourself (DRY) principle.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/keys/createApiKeyHandler.ts` around lines 19 - 23, Extract the repeated
auth gate into a small reusable helper (e.g., getAuthAccountId or requireAuth)
that wraps validateAuthContext, checks for "instanceof NextResponse" and either
returns the extracted { accountId } or the NextResponse directly; then replace
the duplicate block in createApiKeyHandler (and the other two key handlers) with
a call to this helper and early-return when it yields a NextResponse. Ensure the
helper exposes a clear return type (union of accountId payload or NextResponse)
and update callers to destructure accountId after the helper returns a success
value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/keys/createApiKeyHandler.ts`:
- Around line 19-23: Extract the repeated auth gate into a small reusable helper
(e.g., getAuthAccountId or requireAuth) that wraps validateAuthContext, checks
for "instanceof NextResponse" and either returns the extracted { accountId } or
the NextResponse directly; then replace the duplicate block in
createApiKeyHandler (and the other two key handlers) with a call to this helper
and early-return when it yields a NextResponse. Ensure the helper exposes a
clear return type (union of accountId payload or NextResponse) and update
callers to destructure accountId after the helper returns a success value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1709eb74-1eaa-4b5b-a98c-38d9172aa499

📥 Commits

Reviewing files that changed from the base of the PR and between 1b06393 and 140185d.

📒 Files selected for processing (3)
  • lib/keys/createApiKeyHandler.ts
  • lib/keys/deleteApiKeyHandler.ts
  • lib/keys/getApiKeysHandler.ts

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