Skip to main content

RecaptchaConfig

Package: @nauth-toolkit/core Type: Interface (Configuration)

Configuration interface for Google reCAPTCHA bot protection.

import { NAuthModuleConfig } from '@nauth-toolkit/nestjs';

Properties

PropertyTypeRequiredDescription
actionScoresRecord<string, number>NoPer-action minimum score overrides. Falls back to minimumScore for unlisted actions. Keys are action names (login, signup, password_reset).
enabledbooleanYesEnable reCAPTCHA validation. When true, routes marked with @RequireRecaptcha() will enforce validation.
minimumScorenumberNoDefault minimum score for v3/Enterprise (0.0-1.0). Used when no per-action override exists in actionScores. Default: 0.5.
providerRecaptchaProviderYesProvider implementation: RecaptchaV2Provider, RecaptchaV3Provider, or RecaptchaEnterpriseProvider.
validateOnStartup'warn' | 'error' | falseNoValidate credentials at startup by probing Google's API. 'warn' (default): log warning on failure. 'error': throw and halt startup. false: skip validation.

Examples

import { NAuthModule } from '@nauth-toolkit/nestjs';
import { RecaptchaV3Provider } from '@nauth-toolkit/recaptcha';

@Module({
imports: [
NAuthModule.forRoot({
recaptcha: {
enabled: true,
provider: new RecaptchaV3Provider({
secretKey: process.env.RECAPTCHA_V3_SECRET_KEY!,
}),
minimumScore: 0.5,
},
}),
],
})
export class AppModule {}

// In your controller, mark protected endpoints:
@Controller('auth')
export class AuthController {
@Public()
@RequireRecaptcha()
@Post('login')
async login(@Body() dto: LoginDTO) {
return this.authService.login(dto);
}
}

Enterprise

import { RecaptchaEnterpriseProvider } from '@nauth-toolkit/recaptcha';

@Module({
imports: [
NAuthModule.forRoot({
recaptcha: {
enabled: true,
provider: new RecaptchaEnterpriseProvider({
projectId: process.env.RECAPTCHA_PROJECT_ID!,
apiKey: process.env.RECAPTCHA_API_KEY!,
siteKey: process.env.RECAPTCHA_SITE_KEY!,
}),
minimumScore: 0.7,
actionScores: {
login: 0.3, // More permissive for returning users
signup: 0.7, // Stricter for new registrations
},
},
}),
],
})