From c7642237d5935bd6392275d9a330cf90d1ab6740 Mon Sep 17 00:00:00 2001 From: Jimmy Li Date: Wed, 8 Jan 2025 16:49:15 -0800 Subject: [PATCH] Update to use the helper function instead of depending on instance state --- src/utils/humanity-check.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/humanity-check.js b/src/utils/humanity-check.js index 43f0d70d..46eb7212 100644 --- a/src/utils/humanity-check.js +++ b/src/utils/humanity-check.js @@ -19,7 +19,7 @@ const humanEvents = [ class HumanityCheck { constructor() { // Check if a human event has been performed in the past - this.hasPerformedHumanEvent = !!store.session.get(storageKey) || false; + this.hasPerformedHumanEvent = this.getIsHumanFromSessionStorage(); // Humanity proved, remove handlers const remove = () => { @@ -39,6 +39,11 @@ class HumanityCheck { } } + // Helper function to grab the human variable from session storage + getIsHumanFromSessionStorage() { + return !!store.session.get(storageKey) || false; + } + // Return boolean indicating if user is a bot // ...if it has a bot-like useragent // ...or uses webdriver @@ -53,7 +58,7 @@ class HumanityCheck { } // If the user hasn't performed a human event, it indicates it is a bot - if (!this.hasPerformedHumanEvent) { + if (!this.getIsHumanFromSessionStorage()) { return true; }