Native Convex component for API key management with SHA-256 hashing, rate limiting, RBAC, usage credits, and audit logging within Convex transactions.
npm install @00akshatsinha00/convex-api-keysA convex api keys component for Convex.
Use convex-api-keys to create, verify, and manage API keys entirely within Convex. The component handles SHA-256 hashing, stores keys securely, and provides verification mutations that check validity, rate limits, and usage credits in a single atomic operation.
The convex-api-keys component provides sliding window rate limiting with per-key and per-owner overrides. Configure limits during key creation and the verify mutation automatically enforces them with transactional consistency.
Create permissions and roles, then assign them to API keys using the component's RBAC system. The verify mutation returns permissions, and you can use hasPermission() to check authorization for specific endpoints or actions.
The component automatically logs all verification attempts and creates hourly/daily analytics rollups. Query usage stats, top keys by usage, and build reactive dashboards that update in real-time as API calls are made.
The convex-api-keys component uses SHA-256 hashing to store keys, meaning plaintext keys never persist in the database. Only the hashed version is stored, and the component generates cryptographically secure keys with configurable entropy using base62 encoding.
Yes, convex-api-keys supports usage credits with automatic refill intervals (hourly, daily, weekly, monthly). You can configure different credit amounts for different pricing tiers and the verify mutation automatically decrements credits while enforcing limits.
Yes, convex-api-keys supports multi-tenancy through namespaces and owner isolation. Each key has an ownerId and optional namespace, allowing you to segregate keys by customer, organization, or environment while maintaining data isolation.
The convex-api-keys component provides key rotation with configurable grace periods. During rotation, both the old and new keys remain valid for the specified grace period, allowing clients to migrate without service interruption.
The component includes comprehensive audit logging, automatic analytics rollups with time-bucketed queries, usage statistics per key, and top keys ranking by usage. All data is reactive, so dashboards built with Convex queries update in real-time.