refactor: extract auth rate-limit storage adapter to dedicated module#307
Merged
Merged
Conversation
better-auth logs "Rate limiting is best-effort" and falls back to a non-atomic get-then-set check whenever its secondaryStorage lacks an increment(key, ttl) method. Add createAuthSecondaryStorage(), which wraps the Cloudflare KV / fsLite-backed wolfstar:auth-ratelimiter mount with a fixed-window increment guarded by an in-process keyed mutex (same pattern as server/utils/wrappedEventHandler.ts), so better-auth uses its atomic consume path instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L3DbZF2CQPuxRnBFWHjVxS
Adds dotenv, dotenvx, and vite-plus entries picked up by `skilld prepare` during `pnpm install`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L3DbZF2CQPuxRnBFWHjVxS
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #307 +/- ##
==========================================
+ Coverage 71.53% 71.59% +0.05%
==========================================
Files 167 168 +1
Lines 3302 3323 +21
Branches 702 706 +4
==========================================
+ Hits 2362 2379 +17
Misses 447 447
- Partials 493 497 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The skilld lockfile sync committed absolute symlinks (dotenv, dotenvx, vite-plus) pointing at /home/user/.../node_modules paths that only exist on the author's machine, so they resolve to broken skills in any fresh checkout or CI workspace. Remove the symlinks and their shipped lock entries. Co-authored-by: Codesmith <codesmith-bot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
N/A
🧭 Context
The auth rate-limit storage adapter in
server/auth.config.tswas a simple inline implementation. This change extracts it into a dedicated module (server/utils/auth-rate-limit-storage.ts) to improve maintainability and enable comprehensive testing of the rate-limiting logic.📚 Description
Changes:
New module:
server/utils/auth-rate-limit-storage.tscreateAuthSecondaryStorage()function that adapts a Nitro/unstorage mount to better-auth'sSecondaryStorageinterfaceincrement()method using an in-process keyed mutex (AsyncQueue) to serialize read-modify-write cycles per storage keyUpdated
server/auth.config.tscreateAuthSecondaryStorage()New test file:
test/unit/server/utils/auth-rate-limit-storage.spec.tsThe
increment()method is critical for better-auth's rate limiter to use its single-stepconsumepath instead of falling back to a non-atomic get-then-set operation that logs a warning.Test Plan:
Added unit tests covering all rate-limiting invariants. Tests pass with the new implementation.
https://claude.ai/code/session_01L3DbZF2CQPuxRnBFWHjVxS
Need help on this PR? Tag
/codesmithwith what you need. Autofix is enabled.Confidence Score: 5/5
Safe to merge with low risk.
The change is a focused refactor with unit tests for the new storage behavior, and the auth configuration continues to match the documented better-auth rate-limit setup.
No files require special attention.
What T-Rex did
Reviews (3): Last reviewed commit: "Merge branch 'main' into claude/better-a..." | Re-trigger Greptile