Overview
Thereset() method removes a rate limit’s state from the database, allowing the next request to start fresh with full capacity.
Using the reset() Method
src/client/index.ts:147-166:
When to Reset Rate Limits
1. Successful Login After Failed Attempts
The most common use case is resetting failed login attempts after a successful login:“Reset a rate limit on successful login”
2. Admin Override
Allow admins to manually reset rate limits for specific users:3. Account Upgrades
Reset limits when a user upgrades their account:4. Testing and Development
Reset limits in test code to ensure clean state:Real Example from Source Code
Fromexample/convex/example.ts:106-129:
Resetting Specific Keys vs Global
- Reset Specific Key
- Reset Global Limit
Reset the rate limit for a specific user/key:This only affects the specified key. Other users’ rate limits are unaffected.
Sharding Behavior
From the documentation:“Reset a rate limit to reset, including all shards.”When you reset a rate limit that uses sharding, all shards are reset:
Fixed Window Behavior
From the documentation:
“Note: In the case of a fixed window without a specified start, the new window will be a random time.”
When you reset a fixed window rate limit:
- If the config specifies a
starttime, the window aligns to that - If no
startis specified, a new random start time is chosen
What Happens After Reset
After callingreset(), the rate limit behaves as if it was never used:
Best Practices
Only reset after successful operations
Only reset after successful operations
For security-sensitive operations like login attempts, only reset after confirming success:
Log reset operations
Log reset operations
Keep an audit trail of when limits are reset:
Use with caution for abuse prevention
Use with caution for abuse prevention
Be careful about providing reset functionality to users for security-critical limits:
Consider partial resets for UX
Consider partial resets for UX
Instead of full reset, you might want to just add capacity:
Common Patterns
Password Reset Flow
Free Trial to Paid Conversion
Next Steps
- Learn about Error Handling with rate limits
- Understand Checking Limits without consuming
- Explore Basic Usage for getting started