Recently I’ve been experimenting with Truecaller SDK in React Native. React-native-truecaller-sdk can be used as an alternate method of authenticating users for login/signup. However, it can be difficult to configure the app correctly if you’re new. I am going to guide you through setting up a simple truecaller based authentication in React Native.
(Note: The module is currently supported for Android only)
1. Install & link package
Enter the following command in your project directory
npm install react-native-truecaller-sdk — save
If you are running RN version > 0.60 you can skip the next command as React Native links the libraries itself in the latest versions.
npm link react-native-truecaller-sdk
2. Create Application on Truecaller dashboard
Now visit https://developer.truecaller.com/login and create account (if you have not yet created one) and login to truecaller dashboard. Create an app on this dashboard which will be used by truecaller to identify your application.
The following information will be required to create an app.
The goal is to generate an app key [ partner key ] from Truecaller developer account by adding your app name, package name and your app’s SHA-1 key.
You can get your app’s SHA-1 key for different app builds configs (debug/release) by following 3 simple steps:
- Open your project in android studio
- Click on gradle menu on the right side and expand it
- Click on android and then signing report
NOTE: Different app builds ( debug / release ) have different SHA1 fingerprints and hence would have different & unique app keys, as a single app key corresponds to a particular combination of package name and SHA-1. You need to manage your debug / release builds by creating separate keys.
Fill in the App name, package name and your correct ( as per build config) SHA-1 key and hit ‘Create App’. You will be navigated into the following screen, copy the App Key.
3. App side Setup and Configuration
Open your AndroidManifest.xml file and add the following meta-data element to the application tag.
<meta-data android:name="com.truecaller.android.sdk.PartnerKey" android:value="@string/truecaller_appkey"/>
Now open your strings.xml file and add a new string tag with the name “truecaller_appkey” and value as your “appKey” the one you copied from the truecaller dashboard.
4. Complete Class Code
Refer to the following class for complete code for truecaller implementation