Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
react-native-recaptcha-enterprise
Advanced tools
Google Enterprise reCaptcha library for React-Native. Real native implementation for iOS and Adnoird.
Google Enterprise reCaptcha. Implemented through native platforms. Support iOS and Android
via NPM
npm install react-native-recaptcha-enterprise
via Yarn
yarn add react-native-recaptcha-enterprise
In example folder there is simple workflow how to:
How it looks like you can see here
Not init session | Executed action (login) |
Error unavailable (no Google Play Service) | Error from native part (with code and description) |
Important: All methods are promise based and can throw exceptions. List of errors is provided in Error handling section
It is better to call it somewhere in the startup and use as Singleton
instance further
import { initializeRecaptcha } from 'react-native-recaptcha-enterprise';
await initializeRecaptcha('YOUR_SITE_KEY');
This method works only on initialized reCaptcha client see initialization upper.
There is only one constant action-name - LOGIN
. Another as VIEWED_CART
, SIGNIN
could be added by request.
You can pass any custom action name here, but it will be prefixed with string constant custom_
import { executeAction } from 'react-native-recaptcha-enterprise';
const executeResult = await executeAction('YOUR_ACTION_NAME');
console.info('Token verify: ', executeResult);
In some cases this library doesn't work on native level. The reason why it happens - missing Google Play Service
(gms package). It could be a real case of you end users as some smartphones doesn't have Google environment at all as Xiaomi, Huawei etc. So it is recomended to check it before, or you can handle error in initialization handler
by:
errorCode === RecaptchaErrorCodes.NotAvailable
As availability check is called on native part during initialization too.
Implementation of direct method call:
const checkAvailability = useCallback(async () => {
try {
setInProgress(true);
const canUseResult = await canUseRecaptcha();
if (canUseResult.result) {
setCanUse(true);
return;
}
setCanUse(false);
Alert.alert(
'ReCaptcha Availability',
'Google ReCaptcha can not be used. Reason: ' + canUseResult.reason
);
} catch (e: any) {
setError(`${e?.message}[code: ${e?.code}]`);
} finally {
setInProgress(false);
}
}, []);
List of supported events:
export enum RecaptchaErrorCodes {
'NotInitializedClient' = 'NotInitializedClient',
'NotAvailable' = 'NotAvailable',
/* Android: UNKNOWN_ERROR, ios: RecaptchaErrorCodeUnknown */
'RecaptchaErrorCodeUnknown' = 0,
/* Android: NETWORK_ERROR, ios: RecaptchaErrorNetworkError */
'RecaptchaErrorNetworkError' = 1,
/* Android: INVALID_SITEKEY, ios: RecaptchaErrorInvalidSiteKey */
'RecaptchaErrorInvalidSiteKey' = 2,
/* Android: INVALID_KEYTYPE, ios: RecaptchaErrorInvalidKeyType */
'RecaptchaErrorInvalidKeyType' = 3,
/* Android: INVALID_PACKAGE_NAME, ios: RecaptchaErrorInvalidPackageName */
'RecaptchaErrorInvalidPackageName' = 4,
/* Android: INVALID_ACTION, ios: RecaptchaErrorInvalidAction */
'RecaptchaErrorInvalidAction' = 5,
/* Android: INTERNAL_ERROR, ios: RecaptchaErrorCodeInternalError */
'RecaptchaErrorCodeInternalError' = 100,
}
All throwable exception from native part has common object structure:
export type RecaptchaErrorType = {
code: RecaptchaErrorCodes;
message: string;
rawData: any;
};
Where:
You can handle it with Promise.catch().then()
approach - classical Promise resolving or use modern one - async/await
in combination with try/catch
statement.
Short example:
try {
setInProgress(true);
const executeResult = await executeAction(actionName);
setToken(executeResult);
} catch (e: any) {
// Where: e - is RecaptchaErrorType
console.log(`${e?.message}[code: ${e?.code}]`);
} finally {
setInProgress(false);
}
See the contributing guide guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
Google Enterprise reCaptcha library for React-Native. Real native implementation for iOS and Android.
The npm package react-native-recaptcha-enterprise receives a total of 78 weekly downloads. As such, react-native-recaptcha-enterprise popularity was classified as not popular.
We found that react-native-recaptcha-enterprise demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.