Skip to content

Commit e412ab2

Browse files
committed
fix: signup verify error
1 parent acf2bc6 commit e412ab2

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

apps/nestjs-backend/src/features/auth/local-auth/local-auth.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ export class LocalAuthController {
123123
const remoteIp =
124124
req.ip || req.connection.remoteAddress || (req.headers['x-forwarded-for'] as string);
125125

126-
return this.authService.sendSignupVerificationCode(body.email, body.turnstileToken, remoteIp);
126+
return this.authService.sendSignupVerificationCodeWithTurnstile(
127+
body.email,
128+
body.turnstileToken,
129+
remoteIp
130+
);
127131
}
128132

129133
@Patch('/change-password')

apps/nestjs-backend/src/features/auth/local-auth/local-auth.service.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,21 @@ export class LocalAuthService {
259259
return res;
260260
}
261261

262-
async sendSignupVerificationCode(email: string, turnstileToken?: string, remoteIp?: string) {
262+
async sendSignupVerificationCodeWithTurnstile(
263+
email: string,
264+
turnstileToken?: string,
265+
remoteIp?: string
266+
) {
263267
this.logger.log(
264268
`Send verification code attempt - email: ${email}, hasTurnstileToken: ${!!turnstileToken}, tokenLength: ${turnstileToken?.length}, remoteIp: ${remoteIp}`
265269
);
266270

267271
// Validate Turnstile token if enabled
268272
await this.validateTurnstileIfEnabled(turnstileToken, remoteIp);
273+
return this.sendSignupVerificationCode(email);
274+
}
269275

276+
async sendSignupVerificationCode(email: string) {
270277
// Check rate limit: ensure interval between emails for the same address
271278
// Backend rate limit is configured limit - 2 seconds (to account for network latency)
272279
// If configured limit is 0, skip rate limiting entirely
@@ -278,9 +285,7 @@ export class LocalAuthService {
278285
const existingRateLimit = await this.cacheService.get(rateLimitKey);
279286

280287
if (existingRateLimit) {
281-
this.logger.warn(
282-
`Signup verification rate limit exceeded - email: ${email}, remoteIp: ${remoteIp}, timestamp: ${new Date().toISOString()}`
283-
);
288+
this.logger.warn(`Signup verification rate limit exceeded - email: ${email}`);
284289
throw new BadRequestException(
285290
`Please wait ${configuredLimit} seconds before requesting a new code`
286291
);
@@ -299,7 +304,7 @@ export class LocalAuthService {
299304

300305
// Log verification code sending
301306
this.logger.log(
302-
`Sending signup verification code - email: ${email}, remoteIp: ${remoteIp}, timestamp: ${new Date().toISOString()}, turnstileVerified: ${!!turnstileToken}`
307+
`Sending signup verification code - email: ${email}, timestamp: ${new Date().toISOString()}`
303308
);
304309

305310
const emailOptions = await this.mailSenderService.sendEmailVerifyCodeEmailOptions({

0 commit comments

Comments
 (0)