capacitor-recaptcha-v3
v0.0.3
Published
reCAPTCHA Enterprise Capacitor Plugin
Readme
capacitor-recaptcha-v3
reCAPTCHA Enterprise Capacitor Plugin
This plugin provides reCAPTCHA Enterprise functionality for Capacitor applications on iOS and Android platforms. It's based on the Google Cloud reCAPTCHA Enterprise React Native module.
Features
- ✅ iOS and Android support
- ✅ TypeScript support
- ✅ Promise-based API
- ✅ Built-in action types (LOGIN, SIGNUP)
- ✅ Custom action support
- ✅ Timeout configuration
- ✅ Error handling
Install
npm install capacitor-recaptcha-v3
npx cap syncSetup
iOS Setup
- Add the following to your
ios/App/Podfile:
use_frameworks! :linkage => :static
# Disable Flipper for static linking compatibility
flipper_config = FlipperConfiguration.disabled- Run pod install:
cd ios && pod install && cd ..Android Setup
No additional setup required for Android.
Usage
Basic Usage
import { CapacitorRecaptchaV3, RecaptchaAction } from 'capacitor-recaptcha-v3';
// Fetch a reCAPTCHA client
const client = await CapacitorRecaptchaV3.fetchClient('your-site-key-here');
// Execute reCAPTCHA with login action
const token = await client.execute(RecaptchaAction.LOGIN());
console.log('Token:', token);Using Different Actions
// Built-in actions
const loginToken = await client.execute(RecaptchaAction.LOGIN());
const signupToken = await client.execute(RecaptchaAction.SIGNUP());
// Custom actions
const purchaseToken = await client.execute(RecaptchaAction.custom('purchase'));
const commentToken = await client.execute(RecaptchaAction.custom('comment'));With Timeout
// Execute with 10 second timeout
const token = await client.execute(RecaptchaAction.LOGIN(), 10000);Error Handling
try {
const client = await CapacitorRecaptchaV3.fetchClient('your-site-key-here');
const token = await client.execute(RecaptchaAction.LOGIN());
console.log('Success:', token);
} catch (error) {
console.error('Error:', error);
}Deprecated Methods (for backward compatibility)
// Initialize client (deprecated)
const initResult = await CapacitorRecaptchaV3.initClient('your-site-key-here', 5000);
// Execute directly (deprecated)
const token = await CapacitorRecaptchaV3.execute(RecaptchaAction.LOGIN(), 5000);API
fetchClient(...)
fetchClient({ siteKey }: { siteKey: string; }) => Promise<RecaptchaClient>Fetches a reCAPTCHA client immediately
| Param | Type | Description |
| --------- | --------------------------------- | ------------------------------------- |
| __0 | { siteKey: string; } | Your application's reCAPTCHA site key |
Returns: Promise<RecaptchaClient>
initClient(...)
initClient({ siteKey, timeout }: { siteKey: string; timeout?: number; }) => Promise<void>Initialize a reCAPTCHA client
| Param | Type | Description |
| --------- | --------------------------------------------------- | ------------------------------------- |
| __0 | { siteKey: string; timeout?: number; } | Your application's reCAPTCHA site key |
execute(...)
execute({ action, timeout }: { action: string; timeout?: number; }) => Promise<{ token: string; }>Execute reCAPTCHA and retrieve a token
| Param | Type | Description |
| --------- | -------------------------------------------------- | ------------------------------------------------------------------- |
| __0 | { action: string; timeout?: number; } | An action string to describe what the user is doing such as "login" |
Returns: Promise<{ token: string; }>
Interfaces
RecaptchaClient
| Method | Signature | | ----------- | ------------------------------------------------------------------------------------------------------------------- | | execute | (action: RecaptchaAction, timeout?: number | undefined) => Promise<string> |
RecaptchaAction
| Prop | Type |
| ------------ | ------------------- |
| action | string |
Development
Building
npm run buildTesting
npm run verifyLinting
npm run lintCommon Issues
iOS Build Issues
If you encounter build issues on iOS, make sure:
- You're using static linking in your Podfile
- Flipper is disabled
- You've run
pod installafter adding the plugin
Android Build Issues
If you encounter build issues on Android, make sure:
- Your Android SDK is properly configured
- You've synced the project with
npx cap sync
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT
Acknowledgments
This plugin is based on the Google Cloud reCAPTCHA Enterprise React Native module.
