Skip to content

Conversation

@boris-w
Copy link
Contributor

@boris-w boris-w commented Oct 24, 2025

No description provided.

@boris-w boris-w requested review from Copilot and tea-artist October 24, 2025 09:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements rate limiting for email verification codes across signup, password reset, and email change flows. The changes refactor existing rate limit logic into a centralized service and extend it to cover all email verification scenarios.

  • Consolidates rate limit configuration from authConfig to thresholdConfig with separate settings for each email flow
  • Introduces a reusable checkSendMailRateLimit method in MailSenderService to handle rate limiting consistently
  • Adds UI countdown timers using a new useCutDown hook to display remaining wait time to users

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/openapi/src/admin/setting/get-public.ts Replaces single rate limit field with three separate fields for different email verification flows
packages/common-i18n/src/locales/*/common.json, auth.json Adds localized error messages for rate limit violations
apps/nextjs-app/src/lib/server-env.ts Adds type definitions for new rate limit configuration fields
apps/nextjs-app/src/features/auth/pages/ResetPasswordPage.tsx Improves error handling type annotations
apps/nextjs-app/src/features/auth/pages/ForgetPasswordPage.tsx Implements countdown timer and rate limit error handling for password reset
apps/nextjs-app/src/features/auth/components/SignForm.tsx Extracts countdown logic to reusable hook and updates field references
apps/nextjs-app/src/features/app/hooks/useSetting.ts Adds new query hook for public settings
apps/nextjs-app/src/features/app/hooks/useCutDown.ts Creates reusable countdown timer hook
apps/nextjs-app/src/features/app/components/setting/account/ChangeEmailDialog.tsx Implements countdown timer and rate limit error handling for email change
apps/nestjs-backend/src/features/setting/open-api/setting-open-api.controller.ts Updates controller to use new threshold config fields
apps/nestjs-backend/src/features/mail-sender/mail-sender.service.ts Adds centralized rate limiting method with cache-based tracking
apps/nestjs-backend/src/features/auth/local-auth/local-auth.service.ts Refactors email sending to use new centralized rate limiting
apps/nestjs-backend/src/configs/threshold.config.ts Moves rate limit config with backward compatibility and adds new fields
apps/nestjs-backend/src/configs/auth.config.ts Removes old rate limit field
apps/nestjs-backend/src/cache/types.ts Updates cache key types to reflect new generic rate limit pattern

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 38 to 40
process.env.BACKEND_SIGNUP_VERIFICATION_CODE_RATE_LIMIT_SECONDS ??
process.env.BACKEND_SIGNUP_VERIFICATION_SEND_MAIL_CODE_RATE ??
30
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback chain for signupVerificationSendMailCodeRate creates an implicit dependency on deprecated environment variable BACKEND_SIGNUP_VERIFICATION_CODE_RATE_LIMIT_SECONDS. Consider documenting this backward compatibility in a comment or setting a deprecation timeline.

Copilot uses AI. Check for mistakes.
if (_rateLimit <= 0) {
return await fn();
}
const rateLimit = _rateLimit - 2; // 2 seconds for network latency
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 2 for network latency adjustment should be extracted to a named constant (e.g., NETWORK_LATENCY_BUFFER_SECONDS = 2) to improve code clarity and maintainability.

Copilot uses AI. Check for mistakes.
return await fn();
}
const rateLimit = _rateLimit - 2; // 2 seconds for network latency
const rateLimitKey = `send-mail-rate-limit:${_rateLimitKey}:${email}` as const;
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The as const assertion on a template literal with variables has no effect since the type cannot be literal. Remove the as const assertion as it provides no type safety benefit here.

Suggested change
const rateLimitKey = `send-mail-rate-limit:${_rateLimitKey}:${email}` as const;
const rateLimitKey = `send-mail-rate-limit:${_rateLimitKey}:${email}`;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant