Sign in with Email/Phone
Our React Native SDK offers the easiest way to integrate Cotter 's email/phone verification. You can simply call a function and it does most of the heavy lifting and authentication for you.
Concepts: Learn about how Sign in with Email/Phone Number works.
Overview
Verifying email and phone number in your mobile app using our React Native SDK consists of the following steps:
Call Cotter's Login function
Setup deep linking
Receive user's email or phone number, and whether or not it's verified
What you're building

Steps
Call Cotter's Verify function: This function will handle the WebView, verifying phone number or email, and request the identity from Cotter's server.
Setup deep linking: Cotter's authentication will redirect back to your application using a URL scheme.
Receive the Token: Include the returned token and email/phone number in your server
Step 1: Import Cotter as a dependency
(Optional) Checkout additional steps for Android, React Native < 0.60, and Manual Installation.
Step 2: Call Cotter's Verify function
Cotter's verify function will open a Custom Chrome Tab or ASWebAuthenticationSession in your app to authenticate the user. You have 2 choices
Open the web browser with no predefined input. The user can enter email or phone in the in-app browser.
2. Open the web browser after the user entered their email or phone number in your app's input field
Try this now! You should see an in-app browser looking like the image below popping up and ask you to authenticate.

Send Code via WhatsApp
Instead of using SMS, you can also send the verification code via WhatsApp.
Step 3: Setup Deep Linking
Pick a unique URL scheme for redirecting the user back to your app after the verification in the in-app browser is successful. For this example, we'll use myexample://auth_callback .
Setup in Android
Add this in your AndroidManifest.xml
Setup in iOS
Add this in your Info.plist
If you're targeting iOS 9.x or newer, add the following lines to YourApp/ios/YourApp/AppDelegate.m:
If you're targeting iOS 8.x or older, you can use the following code instead, add the following lines to YourApp/ios/YourApp/AppDelegate.m:
If your app is using Universal Links, you'll need to add the following code as well, add the following lines to YourApp/ios/YourApp/AppDelegate.m:
Setup in React Native Project
Try it again! You should see the in-app browser redirecting back after you've successfully verified.
Step 4: Receiving the Token in onSuccess or onError
onError
The onError function that you pass in will receive 2 parameters: errorMessage (string) and errorResponse (object). The errorResponse is an http response from attempt to verify the user's email/phone in Cotter's server.
onSuccess
The onSuccess function that you pass in will receive a response object that looks like this:
This JSON object contains 2 objects, identifier and token .
The identifier object contains information about the user's email or phone number, device type and name, and expiry.
The token contains the user's phone number, your
API_KEY_IDin thereceiverfield, and a signature to ensure this is from Cotter. The token tells you that thisidentifieris verified.
You should include this JSON Object into your call to your backend for Login or Registration. Your backend should then verify that the signature of the token is valid.
For example, if you have an existing Register function:
Validating Cotter's Access Token
Checkout how to verify the OAuth Tokens from Cotter here:
Verifying JWT Tokensπ You're done!
Securing your Project
Since you'll be using your API Key from a front-end website or mobile app, your API_KEY_ID is exposed to anyone inspecting your code. Here are some ways to prevent abuse:
Last updated