Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nestlab/google-recaptcha

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestlab/google-recaptcha

Google recaptcha module for NestJS.

  • 1.0.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by6.25%
Maintainers
1
Weekly downloads
 
Created
Source

Google recaptcha module

Usage example here

Install

$ npm i @nestlab/google-recaptcha

Configuration

@Module({
    imports: [
        GoogleRecaptchaModule.forRoot({
            secretKey: process.env.GOOGLE_RECAPTCHA_SECRET_KEY,
            response: req => req.headers.recaptcha,
            skipIf: () => process.env.NODE_ENV !== 'production',
        })
    ],
})
export class AppModule {
}

Usage


@Controller('feedback')
export class FeedbackController {
    @Recaptcha()
    @Post('send')
    async send(): Promise<any> {
        // TODO: Implement it.
    }
}

Error handling

Example error customization. You can return or throw HttpException or return string.

If you will return string, then response will have status code 400 (Bad request).

GoogleRecaptchaModule.forRoot({
    secretKey: process.env.GOOGLE_RECAPTCHA_SECRET_KEY,
    response: req => req.headers.recaptcha,
    skipIf: () => process.env.NODE_ENV !== 'production',
    onError: (errorCodes: ErrorCode[]) => {
        switch (errorCodes.shift()) {
            case ErrorCode.MissingInputSecret:
                return 'The secret parameter is missing.';
            case ErrorCode.InvalidInputSecret:
                return 'The secret parameter is invalid or malformed.';
            case ErrorCode.MissingInputResponse:
                return 'The response parameter is missing.';
            case ErrorCode.InvalidInputResponse:
                return 'The response parameter is invalid or malformed.';
            case ErrorCode.BadRequest:
                return 'The request is invalid or malformed.';
            case ErrorCode.TimeoutOrDuplicate:
                return 'The response is no longer valid: either is too old or has been used previously.';
            case ErrorCode.UnknownError:
            default:
                return new BadGatewayException('Unknown error when checking captcha.');
        }
    },
})

Enjoy!

Keywords

FAQs

Package last updated on 23 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc