A comprehensive example application demonstrating how to integrate and use Twilio Verify Push in React Native for implementing secure two-factor authentication (2FA).
- β Create push verification factors with Twilio Verify
- β Random identity generator for quick testing
- β Network connectivity indicator
- β Automatic factor verification
- β Check SDK availability
- β Clear local storage
- β List all registered factors
- β Pull-to-refresh factor list
- β View detailed factor information
- β Delete factors with confirmation
- β Interactive factor selection
Before running this app, you need:
- Twilio Account: Sign up at twilio.com
- Twilio Verify Service: Create a Verify service in the Twilio Console
- Backend Server: A server endpoint that generates Twilio Access Tokens
- React Native Environment: Set up according to React Native docs
- Clone and install dependencies:
cd verify-react-native-example
npm install- Install iOS dependencies (iOS only):
cd ios && pod install && cd ..- Run the app:
# Android
npx react-native run-android
# iOS
npx react-native run-iosYour backend must provide an endpoint that:
- Accepts a POST request with
{ identity: string } - Returns a JSON response with:
{
"token": "eyJ...", // Twilio Access Token (JWT)
"serviceSid": "VAxxxxx", // Your Verify Service SID
"identity": "hashed_value", // User identity (can be hashed)
"factorType": "push"
}In the app, update the default URL in CreateFactorScreen:
const [accessTokenUrl, setAccessTokenUrl] = useState<string>(
'https://your-backend.com/access-token', // Update this
);Example Node.js backend code:
const twilio = require('twilio');
const AccessToken = twilio.jwt.AccessToken;
const VoiceGrant = AccessToken.VoiceGrant;
app.post('/access-token', (req, res) => {
const { identity } = req.body;
// Create access token
const token = new AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY,
process.env.TWILIO_API_SECRET,
{ identity },
);
// Add Verify grant
const grant = new VoiceGrant({
pushCredentialSid: process.env.PUSH_CREDENTIAL_SID, // Optional
});
token.addGrant(grant);
res.json({
token: token.toJwt(),
serviceSid: process.env.VERIFY_SERVICE_SID,
identity: identity,
factorType: 'push',
});
});- Navigate to the Create Factor tab
- Click the π² button to generate a random identity (or enter your own)
- Verify the Access Token URL is correct
- Press Create Verification Factor
- The factor will be created and verified automatically
- Navigate to the Manage Factors tab
- See all registered factors with their status
- Tap any factor to view detailed information
- Use the Delete button to remove a factor
- Pull down to refresh the factor list
const isAvailable = await TwilioVerify.isAvailable();import {
PushFactorPayload,
FactorType,
} from '@twilio/twilio-verify-for-react-native';
const factorPayload = new PushFactorPayload(
'My Phone', // Friendly name
serviceSid, // Service SID from backend
identity, // User identity
accessToken, // JWT token from backend
pushToken, // FCM/APNS token
);
const factor = await TwilioVerify.createFactor(factorPayload);import { VerifyPushFactorPayload } from '@twilio/twilio-verify-for-react-native';
const verifyPayload: VerifyPushFactorPayload = {
sid: factor.sid,
factorType: FactorType.Push,
};
const verifiedFactor = await TwilioVerify.verifyFactor(verifyPayload);const factors = await TwilioVerify.getAllFactors();
console.log('All factors:', factors);await TwilioVerify.deleteFactor(factorSid);await TwilioVerify.clearLocalStorage();App
βββ NavigationContainer
βββ Tab.Navigator
βββ CreateFactorScreen (Create Factor Tab)
β βββ NetworkIndicator
β βββ Identity Input with Random Generator
β βββ Access Token URL Input
β βββ Create Factor Button
β βββ Actions Section
βββ FactorsListScreen (Manage Factors Tab)
βββ NetworkIndicator
βββ Factor List (FlatList)
β βββ FactorCard (TouchableOpacity)
βββ DetailsPanel (Factor Details)
- Local component state with React hooks (
useState,useEffect) - Network state with
@react-native-community/netinfo - Navigation with React Navigation bottom tabs
Causes:
- Invalid
serviceSid(must start with "VA") - Incorrect or expired
accessToken - Mismatched
identitybetween token and request - Invalid
pushToken(must be real FCM/APNS token for production)
Solution:
- Verify your backend returns the correct
serviceSid - Ensure the
identityin the token matches the one used to create the factor - Use
data.identityfrom backend response (not the input identity) - For production, implement Firebase Cloud Messaging (FCM) or Apple Push Notification Service (APNS)
The app includes a network indicator at the top:
- π’ Green: Connected
- π΄ Red: Not Connected
Ensure you have an active internet connection before creating factors.
Check the console logs for detailed error information:
Full server response:- Shows what your backend returnedAbout to create factor with:- Shows the parameters being sent to Twilio
- Twilio Verify Push Documentation
- Twilio Verify React Native SDK
- Twilio Access Tokens
- React Navigation
- Never hardcode credentials in your React Native app
- Always generate Access Tokens on your backend server
- Validate user identity on the backend before issuing tokens
- Use HTTPS for all backend communications
- Implement proper authentication before allowing factor creation
- Rotate API keys regularly in your Twilio account
- Monitor usage in the Twilio Console to detect anomalies
For production use with real push notifications:
- Create a Firebase project
- Download
google-services.json - Add FCM push credentials to Twilio Console
- Install Firebase libraries:
npm install @react-native-firebase/app @react-native-firebase/messaging - Get FCM token and pass it as
pushToken
- Configure APNS certificates in Apple Developer Portal
- Add push credentials to Twilio Console
- Configure Xcode project for push notifications
- Get APNS token and pass it as
pushToken
This is an example application. Feel free to use it as a starting point for your own Twilio Verify implementation.
This example app is provided as-is for educational purposes.
For Twilio Verify SDK issues:
- GitHub: twilio/twilio-verify-for-react-native
- Twilio Support: support.twilio.com
For general Twilio questions:
- Twilio Docs: twilio.com/docs
- Twilio Community: twilio.com/community
Built with β€οΈ using Twilio Verify and React Native