convex-api-keys

Native Convex component for API key management with SHA-256 hashing, rate limiting, RBAC, usage credits, and audit logging within Convex transactions.

Installation

npm install @00akshatsinha00/convex-api-keys

About convex-api-keys

A convex api keys component for Convex.

Benefits

Use cases

how to add API key authentication to Convex app

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.

implement rate limiting for API keys in Convex

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.

API key role based access control Convex

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.

track API usage analytics in Convex

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.

Frequently asked questions

How does convex-api-keys store API keys securely?

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.

Can I use this component for SaaS tiered pricing with usage limits?

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.

Does the component work with multi-tenant applications?

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.

How do I rotate API keys without downtime?

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.

What analytics and monitoring does this component provide?

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.

Links