Refactor CAPTCHA setup verification

Eliminated constant verification of CAPTCHA setup across different modules and refactored the CAPTCHA token verification process. This commit relies on config parameters to decide whether to verify CAPTCHA or not, instead of environment variables. It also reforms the token submission to CAPTCHA service for consistency and clarity.
This commit is contained in:
giancarlo
2024-04-27 19:13:11 +07:00
parent 0616d3b288
commit 84cacb81c2
3 changed files with 35 additions and 37 deletions

View File

@@ -19,12 +19,6 @@ interface HandlerParams<Body> {
body: Body;
}
/**
* @name IS_CAPTCHA_SETUP
* @description Check if the CAPTCHA is setup
*/
const IS_CAPTCHA_SETUP = !!process.env.CAPTCHA_SECRET_TOKEN;
/**
* Enhanced route handler function.
*
@@ -69,7 +63,8 @@ export const enhanceRouteHandler = <
* This function takes a request object as an argument and returns a response object.
*/
return async function routeHandler(request: NextRequest) {
const shouldVerifyCaptcha = params?.captcha ?? IS_CAPTCHA_SETUP;
// Check if the captcha token should be verified
const shouldVerifyCaptcha = params?.captcha ?? false;
// Verify the captcha token if required and setup
if (shouldVerifyCaptcha) {