@nestlab/google-recaptcha
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,1 +0,2 @@ | ||
export declare function Recaptcha(): MethodDecorator; | ||
import { RecaptchaResponseProvider } from '../types'; | ||
export declare function Recaptcha(response?: RecaptchaResponseProvider): MethodDecorator; |
@@ -6,6 +6,7 @@ "use strict"; | ||
const google_recaptcha_guard_1 = require("../guards/google-recaptcha.guard"); | ||
function Recaptcha() { | ||
return common_1.UseGuards(google_recaptcha_guard_1.GoogleRecaptchaGuard); | ||
const provider_declarations_1 = require("../provider.declarations"); | ||
function Recaptcha(response) { | ||
return common_1.applyDecorators(common_1.SetMetadata(provider_declarations_1.RECAPTCHA_RESPONSE_PROVIDER, response), common_1.UseGuards(google_recaptcha_guard_1.GoogleRecaptchaGuard)); | ||
} | ||
exports.Recaptcha = Recaptcha; | ||
//# sourceMappingURL=recaptcha.js.map |
import { CanActivate, ExecutionContext } from '@nestjs/common'; | ||
import { GoogleRecaptchaValidator } from '../services/google-recaptcha.validator'; | ||
import { GoogleRecaptchaGuardOptions } from '../interfaces/google-recaptcha-guard-options'; | ||
import { Reflector } from '@nestjs/core'; | ||
export declare class GoogleRecaptchaGuard implements CanActivate { | ||
private readonly validator; | ||
private readonly reflector; | ||
private readonly options; | ||
constructor(validator: GoogleRecaptchaValidator, options: GoogleRecaptchaGuardOptions); | ||
constructor(validator: GoogleRecaptchaValidator, reflector: Reflector, options: GoogleRecaptchaGuardOptions); | ||
canActivate(context: ExecutionContext): Promise<true | never>; | ||
} |
@@ -20,5 +20,7 @@ "use strict"; | ||
const google_recaptcha_exception_1 = require("../exceptions/google-recaptcha.exception"); | ||
const core_1 = require("@nestjs/core"); | ||
let GoogleRecaptchaGuard = class GoogleRecaptchaGuard { | ||
constructor(validator, options) { | ||
constructor(validator, reflector, options) { | ||
this.validator = validator; | ||
this.reflector = reflector; | ||
this.options = options; | ||
@@ -32,3 +34,6 @@ } | ||
} | ||
const response = await this.options.response(request); | ||
const provider = this.reflector.get(provider_declarations_1.RECAPTCHA_RESPONSE_PROVIDER, context.getHandler()); | ||
const response = provider | ||
? await provider(request) | ||
: await this.options.response(request); | ||
const result = await this.validator.validate(response); | ||
@@ -43,6 +48,7 @@ if (result.success) { | ||
common_1.Injectable(), | ||
__param(1, common_1.Inject(provider_declarations_1.RECAPTCHA_OPTIONS)), | ||
__metadata("design:paramtypes", [google_recaptcha_validator_1.GoogleRecaptchaValidator, Object]) | ||
__param(2, common_1.Inject(provider_declarations_1.RECAPTCHA_OPTIONS)), | ||
__metadata("design:paramtypes", [google_recaptcha_validator_1.GoogleRecaptchaValidator, | ||
core_1.Reflector, Object]) | ||
], GoogleRecaptchaGuard); | ||
exports.GoogleRecaptchaGuard = GoogleRecaptchaGuard; | ||
//# sourceMappingURL=google-recaptcha.guard.js.map |
@@ -0,4 +1,5 @@ | ||
import { RecaptchaResponseProvider } from '../types'; | ||
export interface GoogleRecaptchaGuardOptions { | ||
response: (req: any) => string | Promise<string>; | ||
response: RecaptchaResponseProvider; | ||
skipIf?: () => boolean | Promise<boolean>; | ||
} |
{ | ||
"name": "@nestlab/google-recaptcha", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Google recaptcha module for NestJS.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
export declare const RECAPTCHA_OPTIONS: unique symbol; | ||
export declare const RECAPTCHA_RESPONSE_PROVIDER: unique symbol; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RECAPTCHA_OPTIONS = void 0; | ||
exports.RECAPTCHA_RESPONSE_PROVIDER = exports.RECAPTCHA_OPTIONS = void 0; | ||
exports.RECAPTCHA_OPTIONS = Symbol('RECAPTCHA_OPTIONS'); | ||
exports.RECAPTCHA_RESPONSE_PROVIDER = Symbol('RECAPTCHA_RESPONSE_PROVIDER'); | ||
//# sourceMappingURL=provider.declarations.js.map |
@@ -52,2 +52,17 @@ # Google recaptcha module | ||
You can override default property that contain recaptcha for specific endpoint. | ||
```typescript | ||
@Controller('feedback') | ||
export class FeedbackController { | ||
@Recaptcha(req => req.body.recaptha) | ||
@Post('send') | ||
async send(): Promise<any> { | ||
// TODO: Your implementation. | ||
} | ||
} | ||
``` | ||
If you want use google recaptcha guard in combination with another guards then you can use `@UseGuards` decorator. | ||
@@ -54,0 +69,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25974
41
293
120