Sign In with Email/Phone Number

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. Setup deep linking: Cotter's authentication will redirect back to your application using a URL scheme.

  2. Receive the Token: Include the returned OAuth 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: Signing Up or Logging In

Sign Up: Use the sign up method to:

  • Verify the user's email or phone number

  • Then create a new user in Cotter if successful

  • If you passed-in the email/phone into the function: if your user already exists, it will return an error "User already exists"

  • If you does not pass in the email/phone into the function: users can enter their email/phone in the pop-up browser, but it will NOT check if the user already exists. It will behave like the Log In method below.

Tip: Use the "Sign Up" method and pass in the user's email/phone to differentiate new and existing user. You can have an input text and collect the user's email/phone.

Log In: Use the login method to:

  • To authenticate a user based on their email.

  • If the user doesn't exist, this method will automatically create a new user.

Tip: Use the "Log In" method to login or register user on the same page

Sign Up

  • Magic Link: use cotter.signUpWithEmailLink

  • OTP: use cotter.signUpWithEmailOTP

Sign In

  • Magic Link: use cotter.signInWithEmailLink

  • OTP: use cotter.signInWithEmailOTP

If no email is specified, the user can enter the email in the in-app browser

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 android/app/src/main/AndroidManifest.xml

Setup in iOS

Add this in your ios/<YourAppName>/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 3 objects, identifier , oauth_token and user .

  • The identifier object contains information about the user's email or phone number, device type and name, and expiry.

  • The oauth_token contains an access_token that you can validate in your backend.

  • The user contains the User object in Cotter, which includes a "Cotter User ID". You should associate your user with this Cotter User ID for reference.

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