Skip to content

Commit

Permalink
Merge pull request #14 from chvarkov/develop
Browse files Browse the repository at this point in the history
Pass request object to skipIf callback for per-reuqest skip checking
  • Loading branch information
chvarkov authored Oct 30, 2020
2 parents f7d8df8 + 4ab6f86 commit fd91053
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ npm i @nestlab/google-recaptcha
GoogleRecaptchaModule.forRoot({
secretKey: process.env.GOOGLE_RECAPTCHA_SECRET_KEY,
response: req => req.headers.recaptcha,
skipIf: () => process.env.NODE_ENV !== 'production',
skipIf: async req => process.env.NODE_ENV !== 'production',
useRecaptchaNet: false,
agent: null
})
Expand All @@ -36,13 +36,13 @@ export class AppModule {

**Configuration options**

| Property | | Type | Description |
|-------------------|---|----------------------------|-------------|
| `secretKey` || string | Google recaptcha secret key |
| `response` || (request) => string | Function that returns response (recaptcha token) by request |
| `skipIf` || () => boolean | Function that returns true if you need skip check for development or testing |
| `useRecaptchaNet` || boolean | If your server has trouble connecting to https://www.google.com. You can use https://recaptcha.net instead, just set true |
| `agent` || https.Agent | If you need to use an agent |
| Property | | Type | Description |
|-------------------|---|---------------------------------------------|-------------|
| `secretKey` || string | Google recaptcha secret key |
| `response` || (request) => string | Function that returns response (recaptcha token) by request |
| `skipIf` || (request) => boolean \| Promise\<boolean\> | Function that returns true if you allow the request to skip the recaptcha verification. Useful for involing other check methods (e.g. custom privileged API key) or for development or testing |
| `useRecaptchaNet` || boolean | If your server has trouble connecting to https://www.google.com. You can use https://recaptcha.net instead, just set true |
| `agent` || https.Agent | If you need to use an agent |


If you want import configs from your [ConfigService](https://docs.nestjs.com/techniques/configuration#getting-started) via [custom getter function](https://docs.nestjs.com/techniques/configuration#custom-getter-functions) that will return `GoogleRecaptchaModuleOptions` object.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestlab/google-recaptcha",
"version": "1.1.4",
"version": "1.1.5",
"description": "Google recaptcha module for NestJS.",
"keywords": [
"nest",
Expand Down
2 changes: 1 addition & 1 deletion src/guards/google-recaptcha.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class GoogleRecaptchaGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<true | never> {
const request = context.switchToHttp().getRequest();

const skip = this.options.skipIf ? await this.options.skipIf() : false;
const skip = this.options.skipIf ? await this.options.skipIf(request) : false;

if (skip) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/google-recaptcha-guard-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { RecaptchaResponseProvider } from '../types';

export interface GoogleRecaptchaGuardOptions {
response: RecaptchaResponseProvider;
skipIf?: () => boolean | Promise<boolean>;
skipIf?: (request: any) => boolean | Promise<boolean>;
}

0 comments on commit fd91053

Please sign in to comment.