feat: Agent Signup & Verify endpoints
Merged
RE
7mo ago+1696+1696+0123456789012345678901234567890123456789-0-0-0123456789
Summary
- Add
POST /api/agents/signup— unauthenticated endpoint for agent registrationagent+prefix emails get instant API key on first signup- All other cases (new normal email or existing account) send a 6-digit verification code via Resend
- Uniform response shape prevents email enumeration
- Add
POST /api/agents/verify— unauthenticated endpoint for email verification- Validates code against hash stored in Privy custom_metadata
- Rate-limited to 5 attempts, 24h expiry
- Returns API key on success, clears metadata
- New Privy REST helpers:
createPrivyUser,getPrivyUserByEmail,setPrivyCustomMetadata - Zod validation for both request bodies
- 23 tests across 5 test files (validators, handlers, utility)
Test plan
- All 23 unit tests pass (
pnpm test lib/agents/__tests__/) -
POST /api/agents/signupwithagent+email returnsapi_keyimmediately -
POST /api/agents/signupwith normal email returnsapi_key: nulland sends verification email -
POST /api/agents/signupwith existing account email sends verification code -
POST /api/agents/verifywith correct code returnsapi_key -
POST /api/agents/verifywith wrong code increments attempts and returns 400 -
POST /api/agents/verifyafter 5 failures returns 429 -
POST /api/agents/verifywith expired code returns 400 - Returned
api_keyworks on authenticated endpoints (e.g.GET /api/artists)
🤖 Generated with Claude Code
Summary by cubic
Adds unauthenticated agent signup and email verification endpoints for programmatic onboarding. agent+ emails get an instant API key; others verify via a 6‑digit code with strict rate/expiry checks.
-
New Features
- POST
/api/agents/signup: register by email;agent+gets immediate API key; others get a 6‑digit code. Uniform response shape. CORS and OPTIONS supported. - POST
/api/agents/verify: validate 6‑digit code via Privy metadata (24h expiry, 5 attempts). On success, issue an API key and clear metadata. CORS and OPTIONS supported.
- POST
-
Bug Fixes
- Expiry safety: treat missing or malformed
verification_expires_atas expired (NaN‑guard). - Reliability: on internal signup errors, return 500 (body stays generic) to enable retries and monitoring.
- Correct Privy request body uses
{ address }; consistent hashing viaPRIVY_PROJECT_SECRET; inclusive 6‑digit code range; never return keys if DB insert fails; remove org auto‑assignment from agent signup.
- Expiry safety: treat missing or malformed
Summary by CodeRabbit
-
New Features
- Agent signup endpoint: email-based registration that instantly issues account+API key for agent+ prefixed addresses, and creates accounts or sends verification codes for other addresses.
- Agent verification endpoint: submit a 6-digit code to receive an API key for verified accounts.
- Email delivery and external user management integrated; CORS preflight supported.
-
Safety / Reliability
- Verification safeguards: code expiry (24h) and max failed attempts (5).
- Consistent error handling and fallback responses.