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:

  1. Call Cotter's Login function

  2. Setup deep linking

  3. Receive user's email or phone number, and whether or not it's verified

What you're building

Cotter's React Native SDK on Android and iOS

Steps

  1. Call Cotter's Verify function: This function will handle the WebView, verifying phone number or email, and request the identity from Cotter's server.

  2. Setup deep linking: Cotter's authentication will redirect back to your application using a URL scheme.

  3. Receive the Token: Include the returned token and email/phone number in your server

Step 1: Import Cotter as a dependency

Make sure you're using react-native version < 0.63

(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

  1. 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

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

In your App.js

If you have Nested Stack Navigator, add path: '' to every parent stack.

Remember to make sure your callbackURL in Step 2 is correct.

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_ID in the receiver field, and a signature to ensure this is from Cotter. The token tells you that this identifier is verified.

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