Overview
Resonance uses Clerk for authentication and provides two procedure types for protected API access:- authProcedure - Requires authenticated user (userId only)
- orgProcedure - Requires organization context (userId + orgId)
Procedure Types
Base Procedure
Unprotected procedure available to all requests.src/trpc/init.ts
Auth Procedure
Requires a valid user session. ThrowsUNAUTHORIZED if user is not signed in.
src/trpc/init.ts
Clerk user ID available in the procedure context
Org Procedure
Requires both user authentication and organization membership. This is used for all voice and generation operations.src/trpc/init.ts
Clerk user ID
Clerk organization ID (required for voice and generation operations)
Authentication Flow
Middleware Validation
Each tRPC procedure validates the session:
authProcedurechecks for userIdorgProcedurechecks for both userId and orgId
Error Responses
UNAUTHORIZED (401)
Thrown when no valid user session exists.FORBIDDEN (403)
Thrown when user is authenticated but lacks organization context.Usage in Routers
All Resonance API routers useorgProcedure to ensure organization-scoped access:
Monitoring
All procedures include Sentry middleware for error tracking and performance monitoring:- RPC input parameters
- Error stack traces
- Request timing information