Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

accept token as obj or string

Blue Mouseab99c3615d4d
diff --git a/src/index.ts b/src/index.ts
index da49a2b6c..13f2daea1 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,19 +3,23 @@ import { makeAPIRequest, ENDPOINTS } from './utils'
/**
* Function to validate the CAPTCHA token.
*
- * @param {string} token The CAPTCHA token.
+ * @param {string | object} token The CAPTCHA token.
* @param {string} secret The secret API key.
- * @param {number} timestamp The timestamp of the CAPTCHA pass.
- * @param {string | null} hash The hash of the CAPTCHA pass.
* @param {string | null} apiURL The API URL to use (default: https://api.swetrix.com/captcha).
* @returns {Promise<[boolean, object | null]>} The result of the validation.
*/
-export async function validateToken(token: string, secret: string, timestamp: number, hash?: string, apiURL?: string): Promise<[boolean, object | string]> {
+export async function validateToken(token: string | any, secret: string, apiURL?: string): Promise<[boolean, object | string]> {
let res
+ let _token = typeof token === 'string' ? token : token?.token
+
+ if (!_token) {
+ return [false, 'CAPTCHA token is missing']
+ }
+
try {
res = await makeAPIRequest(ENDPOINTS.VALIDATE, 'POST', {
- token,
+ token: _token,
secret,
}, apiURL)
} catch (e: any) {