Skip to content

Commit b801175

Browse files
authored
fix: allow to bypass recaptcha via env var (#2133)
1 parent bbac7ba commit b801175

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/services/auth/plugins/captcha/captcha.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { RouteShorthandHook } from 'fastify/types/route';
88
import type { RecaptchaActionType } from '@graasp/sdk';
99

1010
import { DEV } from '../../../../config/env';
11-
import { RECAPTCHA_SECRET_ACCESS_KEY } from '../../../../utils/config';
11+
import { BYPASS_RECAPTCHA, RECAPTCHA_SECRET_ACCESS_KEY } from '../../../../utils/config';
1212
import { AuthenticationError } from './errors';
1313

1414
export const RECAPTCHA_VERIFY_LINK = 'https://www.google.com/recaptcha/api/siteverify';
@@ -43,7 +43,7 @@ async function validateCaptcha(
4343
) {
4444
const shouldFailIfLowScore = options?.shouldFail ?? true;
4545
// TODO: find a better solution? to allow dev
46-
if (DEV) {
46+
if (DEV || BYPASS_RECAPTCHA === true) {
4747
return;
4848
}
4949

src/utils/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'os';
22

33
import { ClientManager, Context, DEFAULT_LANG, GPTVersion, type GPTVersionType } from '@graasp/sdk';
44

5-
import { requiredEnvVar } from '../config/helpers';
5+
import { requiredEnvVar, toBoolean } from '../config/helpers';
66
import type {
77
LocalFileConfiguration,
88
S3FileConfiguration,
@@ -196,6 +196,9 @@ export const EMBEDDED_LINK_ITEM_IFRAMELY_HREF_ORIGIN = requiredEnvVar(
196196
export const IMAGE_CLASSIFIER_API =
197197
process.env.IMAGE_CLASSIFIER_API ?? 'http://localhost:8080/infer';
198198

199+
// allows to bypass captcha validation (for example when running in production)
200+
export const BYPASS_RECAPTCHA = toBoolean(process.env.BYPASS_RECAPTCHA, { default: false });
201+
199202
export const ITEMS_ROUTE_PREFIX = '/api/items';
200203
export const APP_ITEMS_PREFIX = '/api/app-items';
201204
export const THUMBNAILS_ROUTE_PREFIX = '/thumbnails';

0 commit comments

Comments
 (0)