Our React Native SDK offers the easiest way to integrate Cotter's Passwordless Login. You can simply call a function and it does most of the heavy lifting and authentication for you.
To allow Cotter to display modals, wrap your root component with connectCotterWrapper :
import {connectCotterWrapper} from 'react-native-cotter';
class MyApp extends Component {
}
MyApp = 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";
class SignUp extends Component {
...
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
this.onSuccess,
this.onError,
);
};
onSuccess = resp => {
alert('Success');
console.log(resp);
};
onError = err => {
alert('Error');
console.log(err);
};
...
}
Step 4: Authenticate from a Trusted Device and Non-Trusted Device
To request an authentication from Cotter's SDK, you would need to call cotter.signInWithDevice . This will automatically detect whether the current device is a Trusted Device or not.
// Request authentication
var cotter = new Cotter(API_KEY_ID);
cotter.signInWithDevice(
identifier, // User's email, phone or username
this.onSuccess,
this.onError,
);
Cotter's SDK will find the user from userEmail , this must be the same as the one used to register the user during sign up.
use this access_token to protect all of your API endpoints, or
you can use your own session tokens. You'll need to validate this access_token before you generate your session tokens in the backend.
Trusted and Non-Trusted Device
When an Authentication Event is requested using method TRUSTED_DEVICE, there are 2 possible cases:
Case 1: The current device is a Trusted Device
If the current device is a Trusted Device, it should automatically be approved, and you will receive an access token.
{
...
"method": "TRUSTED_DEVICE",
"new": false, // Is this a new pending event (should be false).
"approved": true // Is this event approved (should be true).
"signature": "oonMGCAxp3..." // Signature to make sure this event comes from Cotter's server
}
You should see a result that the event is not new, and that it's approved. You'll receive the oauth_token because the user is successfully authenticated, and you can pass this to your backend to authorize access for the user.
Checkout how to verify the OAuth Tokens from Cotter here:
Case 2: The current device is NOT a Trusted Device
We'll cover this in the next guide:
🎉 You're done!
(Optional) Checkout additional steps .
This function returns oauth_token , including an access_token that you should . You can either:
Cotter's SDK automatically stores the OAuth tokens for you. Check out how to .