@galoymoney/react-native-geetest-module
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

react-native-geetest-module

A React Native Geetest module for gt3 that can protect server endpoints.

Installation

yarn add react-native-geetest-module

or

npm install react-native-geetest-module

then

npx pod-install

App Configuration

Android

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.**{*;}

Usage

This module requires a server with register (API1) and validation (API2) endpoints.

Geetest Flow

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.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Package Sidebar

Install

npm i @galoymoney/react-native-geetest-module

Weekly Downloads

65

Version

0.1.5

License

MIT

Unpacked Size

166 kB

Total Files

31

Last publish

Collaborators

  • galoybot
  • sbgaloy
  • daviroo
  • nbgaloy
  • bodymindarts