A React Native Geetest module for gt3 that can protect server endpoints.
yarn add react-native-geetest-module
or
npm install react-native-geetest-module
then
npx pod-install
In AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
In proguard-rules.pro
-dontwarn com.geetest.sdk.**
-keep class com.geetest.sdk.**{*;}
This module requires a server with register (API1) and validation (API2) endpoints.
Documentation from Geetest is provided here
Set up the module in the component that uses Geetest
import * as React from "react"
import {NativeModules, NativeEventEmitter} from "react-native"
import GeetestModule from "react-native-geetest-module";
// ...
const onGeetestDialogResultListener = React.useRef<EventSubscription>()
const onGeetestFailedListener = React.useRef<EventSubscription>()
// ...
React.useEffect(() => {
GeetestModule.setUp()
const eventEmitter = new NativeEventEmitter(NativeModules.GeetestModule)
onGeetestDialogResultListener.current = eventEmitter.addListener(
"GT3-->onDialogResult-->",
(event) => {
const parsedDialogResult = JSON.parse(event.result)
console.log( "GT3-->onDialogResult-->", parsedDialogResult)
},
)
onGeetestFailedListener.current = eventEmitter.addListener(
"GT3-->onFailed-->",
(event) => {
console.log("GT3-->onFailed->", event.error)
},
)
return () => {
GeetestModule.tearDown()
onGeetestDialogResultListener.current?.remove()
onGeetestFailedListener.current?.remove()
}
}, [])
Call the module with the results from the register request as a json string
GeetestModule.handleRegisteredGeeTestCaptcha(/*
JSON.stringify({
success,
challenge,
gt,
new_captcha,
})
*/)
Then use the parsedDialogResult to validate a call to your server's endpoint.
See the example.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT