HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode.com/builds/-DFbjr9L/0/foach/quadcode.com/src/routes/api/CheckingRecaptcha.ts
import { env } from '$env/dynamic/public';
import WLogger from './WLogger';
import Sanitizing from './Sanitizing';

const CheckingRecaptcha = (token: string) => {
  WLogger.log('info', '[Recaptcha]: START', Sanitizing({ token: token }));

  if (!env?.PUBLIC_RECAPTCHA_SECRET || !env?.PUBLIC_RECAPTCHA_SITE_KEY) {
    WLogger.log('error', '[Recaptcha]: END', {
      error: `PUBLIC_RECAPTCHA_SECRET: undefined || PUBLIC_RECAPTCHA_SITE_KEY: undefined`,
    });
    return;
  }

  const data = {
    secret: env.PUBLIC_RECAPTCHA_SECRET,
    response: token,
  };

  return fetch(`https://www.google.com/recaptcha/api/siteverify`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: new URLSearchParams(Object.entries(data)).toString(),
  })
    .then((response) => response.json())
    .then((response) => {
      return {
        ...response,
        error: ENRecaptchaError[response['error-codes']?.[0]],
      };
    })
    .catch((error) => error);
};

const ENRecaptchaError: { [name: string]: string } = {
  'missing-input-secret': 'The secret parameter is missing.',
  'invalid-input-secret': 'The secret parameter is invalid or malformed.',
  'missing-input-response': 'The response parameter is missing.',
  'invalid-input-response': 'The response parameter is invalid or malformed.',
  'bad-request': 'The request is invalid or malformed.',
  'timeout-or-duplicate	': 'The response is no longer valid: either is too old or has been used previously.',
};

export default CheckingRecaptcha;