feat(auth): add signIn rate-limit backfill with dual ip/account budgets
Wires the rate-limit primitive end-to-end through auth.signIn as the
canonical credential-stuffing defence example:
- manifest: rateLimit [ip 5/1m, account 10/1h] on signIn use case
- use case: rateLimit: IRateLimit dep; dual consume + TooManyRequestsError
- binders: ctx.rateLimit ?? new NoopRateLimit() in bind-production + bind-dev-seed
- tRPC: TooManyRequestsError → TOO_MANY_REQUESTS error code in authProcedure
- tests: RecordingRateLimit dual-consume assertion; InMemoryRateLimit
budget-1 ip + account rejection; coverage 100% on use-cases layer
- ESLint: _manifest-ast.js extractRateLimitNames handles RateLimitBudget
objects ({name,window,budget}) in addition to plain string literals,
no-undeclared-rate-limit passes on both "ip" and "account" call sites
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,3 +18,10 @@ export class UnauthorizedError extends Error {
|
||||
this.name = "UnauthorizedError";
|
||||
}
|
||||
}
|
||||
|
||||
export class TooManyRequestsError extends Error {
|
||||
constructor(message: string, options?: ErrorOptions) {
|
||||
super(message, options);
|
||||
this.name = "TooManyRequestsError";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
AuthenticationError,
|
||||
UnauthenticatedError,
|
||||
UnauthorizedError,
|
||||
TooManyRequestsError,
|
||||
} from "./auth";
|
||||
import { InputParseError } from "./common";
|
||||
|
||||
@@ -37,3 +38,12 @@ describe("InputParseError", () => {
|
||||
expect(err.message).toBe("invalid input");
|
||||
});
|
||||
});
|
||||
|
||||
describe("TooManyRequestsError", () => {
|
||||
it("is an instance of Error with the given message", () => {
|
||||
const err = new TooManyRequestsError("too many attempts");
|
||||
expect(err).toBeInstanceOf(Error);
|
||||
expect(err.message).toBe("too many attempts");
|
||||
expect(err.name).toBe("TooManyRequestsError");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user