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
npm
1
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
2
npx pod-install ios
Copied!
1
npm install --save 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
2
npx pod-install ios
Copied!
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

1
import {connectCotterWrapper} from 'react-native-cotter';
2
​
3
class MyApp extends Component {...}
4
export default connectCotterWrapper(MyApp);
Copied!

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.
JavaScript
Response
1
import { Cotter } from "react-native-cotter";
2
​
3
const register = (identifier) => {
4
// Signup the user and trust this device
5
var cotter = new Cotter(API_KEY_ID);
6
cotter.signUpWithDevice(
7
identifier, // User's email, phone or username
8
(response) => {console.log(response)}, // OnSuccess function
9
(error) => {console.log(error)}, // OnError function
10
);
11
};
Copied!
1
// Returns the newly created User object in Cotter
2
// along with oauth tokens
3
​
4
{
5
"ID": "cccccccc-cccc-cccc-cccc-cccccccccccc",
6
"client_user_id": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
7
"created_at": "2020-06-09T03:50:04.005779Z",
8
"default_method": "TRUSTED_DEVICE",
9
"deleted_at": null,
10
"enrolled": [
11
"TRUSTED_DEVICE"
12
],
13
"identifiers": [
15
],
16
"issuer": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
17
"oauth_token": {
18
"access_token": "eyJhbGciOi...",
19
"auth_method": "TRUSTED_DEVICE",
20
"expires_in": 3600,
21
"id_token": "eyJhbGciOiJFU...",
22
"refresh_token": "6177:MufdKMIk2XP...",
23
"token_type": "Bearer"
24
},
25
"update_at": "2020-06-09T03:50:04.77575278Z"
26
}
Copied!

Step 4️: Logging In from a Trusted Device

Use the signInWithDevice method to login with the same identifier as the one registered above.
JavaScript
Response
1
import { Cotter } from "react-native-cotter";
2
​
3
const login = (identifier) => {
4
var cotter = new Cotter(API_KEY_ID);
5
cotter.signInWithDevice(
6
identifier, // User's email, phone or username
7
(response) => {console.log(response)}, // OnSuccess function
8
(error) => {console.log(error)}, // OnError function
9
);
10
}
Copied!
1
{
2
"ID": 1361, // Event ID
3
"CreatedAt": "2020-02-27T22:22:48.705212512Z",
4
"UpdatedAt": "2020-02-27T22:22:48.705212512Z",
5
"DeletedAt": null,
6
"client_user_id": "1014", // your client's User ID
7
"issuer": "afcabd98-745f-4b9e-98de-af968d9951d3", // your API Key
8
"event": "<EVENT NAME>",// requested event (LOGIN, or TRANSACTION, etc)
9
"ip": "192.168.232.2",
10
"location": "Unknown",
11
"timestamp": "1582842167",
12
"method": "TRUSTED_DEVICE", // auth method: TRUSTED_DEVICE (other choices are PIN / BIOMETRIC)
13
"new": false, // Is this a new pending event. More explanation below about Non-Trusted Device
14
"approved": true, // Is this event approved.
15
"signature": "oonMGCAxp3..." // Signature to make sure this event comes from Cotter's server
16
}
Copied!

πŸŽ‰ 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

πŸ‘‰ What's Next?

Verify User's Email or Phone Number

Logging-in from Another Device

Last modified 11mo ago