Cotter
  • 🚀Getting Started
  • Features & Concepts
    • 💬Sign In with Email/Phone Number
    • 🔐Sign In with Device
      • How it works
    • 🧬Sign In with WebAuthn
  • 📌Quickstart Guides
    • All Guides & Tutorials
    • HTML – Sign in with Email/Phone
    • React – Sign in with Email/Phone
    • React – WebAuthn
    • ▲ Next.js
    • Angular
    • Webflow
    • Bubble.io
    • Python SDK for a CLI
    • React Native – Sign in with Device
    • iOS – Sign in with Device
    • Flutter – Sign in with Device
  • 📘SDK Reference
    • Web
      • Sign In with Email/Phone Number
        • Customize the Form
        • Checking the email or phone before sending a verification code
        • Sending Code or Link via WhatsApp
        • Styling
        • Older SDK
          • Customize the Form
      • Sign in with Social Login
        • Getting Access Tokens from Social Login Providers
        • Github Instructions
        • Google Instructions
      • Sign In with WebAuthn
        • Register WebAuthn for a logged-in user
      • Sign In with Device
        • Steps for Pop Up Authentication Prompt
        • Advanced Customization for Login Form
        • Advanced Customization for Pop Up Authentication Prompt
      • Getting Access Token and Logged-In User Info
      • Sending Successful Form Submission
      • FAQ & Troubleshooting
    • React Native
      • Installation
      • Sign In with Device
        • Add Email/Phone Verification
        • Authenticate from a Non-Trusted Device
        • Add a new Trusted Device
        • Remove Trusted Device
      • Sign In with Email/Phone Number
      • Getting Stored OAuth Tokens and User Information
      • FAQ
      • Older SDK Versions
        • Sign in with Email/Phone
        • Sending Code via WhatsApp
        • Sign In with Device
          • Authenticate from a Non-Trusted Device
          • Add a new Trusted Device
          • Customization
    • Flutter
      • Sign In with Device
        • Add Email/Phone Verification
        • Authenticate from a Non-Trusted Device
      • Sign in with Email/Phone Number
      • Getting the Logged-in User
      • Getting OAuth Tokens
      • Signing a User Out
    • iOS
      • Sign In with Email/Phone Number
      • Sign In with Device
        • Authenticate from a Non-Trusted Device
        • Push Notification
        • Check if Trusted Device is Enrolled
        • Add a New Trusted Device
        • Remove Trusted Device
      • Older Versions
        • Biometric/Pin
    • Android
      • Sign In with Device
        • Authenticate from a Non-Trusted Device
        • Check if Trusted Device is Enrolled
        • Add a new Trusted Device
        • Remove Trusted Device
        • Customization
      • Sign In with Email/Phone Number
      • Biometric/Pin
        • Advanced Methods
        • Customization
        • Setting Strings
        • Styling
      • Older SDK Version
        • Sign In with Device
          • Authenticate from a Non-Trusted Device
    • Python (for CLI)
    • API for Other Mobile Apps or CLI
      • Verify Email/Phone Number
        • Handling URL Scheme
    • Backend: Handling Response
  • 🛡️ Protecting Your Account
    • Only Allow Your Website/App to Use Your API Key
    • Rate Limit
    • Enable reCAPTCHA to Protect Against Automated Abuse
  • 🗝️ Getting Access Token
    • Cotter's OAuth 2.0 Tokens Specification
    • Getting the Tokens
      • Get Tokens during Authentication
      • Using the Refresh Token
    • Storing and Removing Tokens
    • Renewing Expired Tokens
    • Verifying JWT Tokens
    • Requesting Custom Fields on your JWT Token
    • Older API
      • Using HTTP Requests
      • Getting the Tokens
        • During Authentication
          • During Email/Phone Verification
        • During enrolling Trusted Devices
  • 🔌API Reference
    • User API
      • User Object
    • OAuth Tokens API
      • Verify JWT Token using API (serverless)
      • Requesting Custom Claims on your Access Token
      • Older API
    • OAuth Tokens from Social Login
    • Event Object
    • Reset PIN API
  • Older API
    • Validating Cotter's Identity Token
    • Validating Cotter's Event Response
Powered by GitBook
On this page
  • Step 1: Set Up Deep Linking
  • Step 2: Update your Sign Up Function
  • Verifying Before Registering the User
  1. SDK Reference
  2. React Native
  3. Sign In with Device

Add Email/Phone Verification

PreviousSign In with DeviceNextAuthenticate from a Non-Trusted Device

Last updated 4 years ago

Available from version > react-native-cotter@0.3.6

Most of the time, it's required for you to check if the user's identifier (their email or phone number) is valid. With Cotter, you can verify your users via email, SMS, or WhatsApp.

Step 1: Set Up Deep Linking

The verification will follow OAuth's PKCE flow which will open an in-app browser where your user can enter the OTP sent to their email/phone.

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 .

Follow the guide under Sign in with Email/Phone – , then come back to this step.

Step 2: Update your Sign Up Function

Make sure you followed the guide for . Update your .

Verifying Before Registering the User

Verify the email/phone number first, then continue registering the user if verification is successful

This will work the following way:

  1. The user will be asked to verify their email or phone number

  2. If verification successful, we'll create a new User

  3. Then, set up the current device as trusted.

If the user already exists but doesn't have a Trusted Device set up (for example from logging-in to your website):

  1. The user will be asked to verify their email or phone number

  2. Then if verification successful, set up the current device as trusted.

import { Cotter } from "react-native-cotter";

class SignUp extends Component {
  ...
  // Remove your `register` function, and update to the following
  // signupOrLogin function.
  // This function handles both Sign Up and Login
  
  const signupOrLogin = async () => {
    let cotter = new Cotter(API_KEY_ID);

    try {
      // Fetch user using the User API
      // identifier = user's email
      const user = await cotter.getUserByIdentifier(identifier);
      console.log(user);

      if (validUUID(user.ID) && user.enrolled.includes('TRUSTED_DEVICE')) {
        // ========================
        //      Existing User
        // ========================
        // A) User already have a trusted device
        // proceed with SignInWithDevice
        cotter.signInWithDevice(
          identifier,
          resp => console.log('Success', resp),
          errs => console.log('Error', errs),
        );
      } else {
        // ===========================================================
        //      New User OR Existing but No Trusted Device
        // ===========================================================
        // B) User doesn't exists OR exists doesn't have a trusted device
        // 1️⃣ Verify Email
        await cotter.signInWithEmailLink(
          'myexample://auth_callback',
          resp => {
            // 2️⃣  Proceed with registering this device as a trusted device
            registerDeviceAsTrusted();
          },
          err => alert('Error', err),
          {email: identifier},
        );
      }
    } catch (e) {
      alert('Error', err);
    }
  };
  
  const registerDeviceAsTrusted = async () => {
    let cotter = new Cotter(API_KEY_ID);
    const user = await cotter.getLoggedInUser();
    user.registerDevice(
      resp => console.log('Success', resp),
      err => console.log('Error', err),
    );
  };
  ...
}
📘
Sign In with Device
Sign Up Function that you made on Step 3
Step 3: Setting up Deep Linking