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:
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
Setup deep linking: Cotter's authentication will redirect back to your application using a URL scheme.
Receive the Token: Include the returned OAuth 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: 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.signUpWithPhoneLinkOTP: use
cotter.signUpWithPhoneOTP
Sign In
Magic Link: use
cotter.signInWithPhoneLinkOTP: use
cotter.signInWithPhoneOTP
Channels: (default to "SMS" if phone is specified)
To use SMS:
{phone: this.state.phone, channel: "SMS"}To use WhatsApp:
{phone: this.state.phone, channel: "WHATSAPP"}
If no phone number is specified, the user can enter the phone number in the in-app browser and there will be buttons for WhatsApp and SMS available (based on your settings in the Dashboard > Branding).
Try this now! You should see an in-app browser looking like the image below popping up and ask you to authenticate.

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 .
Make sure your URL scheme (the front part before ://) doesn't have an underscore or other special characters. To test it out, enter your Redirect URL here: https://jsfiddle.net/omd02jn5/
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
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:
Please use the identifier (email/phone number) as your main way to identify users, user.ID is deprecated.
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_tokencontains anaccess_tokenthat you can validate in your backend.The
usercontains the User object in Cotter, which includes a "Cotter User ID". You should associate your user with this Cotter User ID for reference.
You should include this JSON Object into your call to your backend for Login or Registration. Your backend should then verify that the access token is valid.
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