React Native – Sign in with Device

Cotter's Passwordless SDK authenticates your user based on their device. It allows a seamless, fast, and secure way for your user to login to your React Native App.

Sign in with Device

In this guide we'll allow users to Sign In with Device using Cotter's SDK.

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

Step 1️: Get Cotter SDK

Head to https://dev.cotter.app/rules and allow Trusted Devices in the dashboard.

yarn add react-native-cotter react-native-device-info rn-secure-storage react-native-randombytes react-native-camera react-native-svg react-native-securerandom buffer react-native-inappbrowser-reborn react-native-sha256
npx pod-install ios

Make sure you use version >= 0.2.0. Checkout additional steps for Android, React Native < 0.60, and Manual Installation.

Step 2️: Wrap your root component with connectCotterWrapper

import {connectCotterWrapper} from 'react-native-cotter';

class MyApp extends Component {...}
export default connectCotterWrapper(MyApp);

Step 3️: Register user and trust this device

This method signUpWithDevice will register the user based on the user's identifier to Cotter and then trust the current device.

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

const register = (identifier) => {
  // Signup the user and trust this device
  var cotter = new Cotter(API_KEY_ID);
  cotter.signUpWithDevice(
    identifier, // User's email, phone or username
    (response) => {console.log(response)}, // OnSuccess function
    (error) => {console.log(error)}, // OnError function
  );
};

Step 4️: Logging In from a Trusted Device

Use the signInWithDevice method to login with the same identifier as the one registered above.

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

const login = (identifier) => { 
    var cotter = new Cotter(API_KEY_ID);
    cotter.signInWithDevice(
        identifier, // User's email, phone or username
        (response) => {console.log(response)}, // OnSuccess function
        (error) => {console.log(error)}, // OnError function
    );
}

🎉 You're Done

Now you can allow your users to Sign In with Device with just 1 tap. When your sessions expires, you can also Sign In User Silently by just calling the method signInWithDevice above.

Find a more detailed version of this guide in our Trusted Devices section

pageSign In with Device

👉 What's Next?

Verify User's Email or Phone Number

pageSign In with Email/Phone Number

Logging-in from Another Device

pageAuthenticate from a Non-Trusted Device

Last updated