verifyAgentToken proves who the User is (email). verifyAgentAccount adds the second step: checking whether that email has an App Account in your database and returning your internal user ID or record.
verifyAgentAccount accepts every verifyAgentToken option plus resolveAccount.
Framework bindings return
{ ok: true, user } onlyWhile verifyAgentAccount returns { ok: true, email, user }, framework bindings (@agentonboard/sdk/next, /express, /hono) return { ok: true, user } so route handlers scope queries by your internal session.user ID.The resolveAccount contract
resolveAccount:
- Receives
{ email }only: Runs only after cryptographic verification succeeds. - Always use
normalizeEmail(email): PassnormalizeEmail(email)(from@agentonboard/sdk) into database queries instead of rawemail.toLowerCase()so case and whitespace match consistently. - Return
nullorundefinedwhen no user exists: Both trigger403 ACCOUNT_REQUIRED. Numeric0and empty string""count as valid user IDs. - Runs once per request: The SDK never caches
resolveAccountresults, so suspended or deleted users lose access immediately. - Exceptions become
500 RESOLVER_ERROR: If your query throws, the SDK catches the error and hides the raw exception message so connection strings cannot leak. Log database errors insideresolveAccountbefore rethrowing.
Handling unknown users: Reject vs. Create
When an email is valid but absent from your database, pick one of two models:When to Reject (Default)
Keep the defaultverifyAgentAccount / requireAgentAccount behavior across all routes if:
- Your API serves existing paying customers, enterprise workspaces, or an invite-only beta.
- New accounts need billing setup, organization assignment, or manual approval before API access.
- You want Users to complete web signup before granting agent access.
When to Create (POST /api/signup)
Add a dedicated POST /api/signup handler with createAgentAccount if:
- Your product is self-serve and you want a User’s agent to register without opening a browser.
- You apply rate limits and abuse controls to self-serve signups.
- You document
POST /api/signupin yourauth.mdfile.
Setting up explicit agent signup (createAgentAccount)
Follow the two-step signup pattern:
1
Guard regular routes with requireAgentAccount
Keep
requireAgentAccount (or verifyAgentAccount) on all regular endpoints so unknown emails receive 403 ACCOUNT_REQUIRED instead of creating accounts as a side effect:app/api/notes/route.ts
2
Add POST /api/signup using createAgentAccount
createAgentAccount verifies the token first, checks resolveAccount, and runs createAccount only when resolveAccount returns null or undefined:app/api/signup/route.ts
createAgentAccount:- Token verified before any database call: Invalid or expired tokens return
401without runningresolveAccountorcreateAccount. - Idempotent on existing users: When
resolveAccountfinds an existing user,createAccountis skipped andoutcome.createdisfalse. - Failed inserts return
500 RESOLVER_ERROR: Exceptions insidecreateAccountreturnRESOLVER_ERRORwith status500. - Your app owns post-signup lifecycle: Welcome emails, rate limits, password setup, and account deletion remain in your application. Revoking an AgentOnboard API Key stops future token minting without deleting App Accounts.
3
Publish POST /api/signup in auth.md
Document
POST /api/signup and reference it in the 403 ACCOUNT_REQUIRED row of your auth.md rejection table. See Publishing auth.md for the full template.