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);
// Fetch user using the User API
// identifier = user's email
const user = await cotter.getUserByIdentifier(identifier);
if (validUUID(user.ID) && user.enrolled.includes('TRUSTED_DEVICE')) {
// ========================
// ========================
// A) User already have a trusted device
// proceed with SignInWithDevice
resp => console.log('Success', resp),
errs => console.log('Error', errs),
// ===========================================================
// New User OR Existing but No Trusted Device
// ===========================================================
// B) User doesn't exists OR exists doesn't have a trusted device
await cotter.signInWithEmailLink(
'myexample://auth_callback',
// 2οΈβ£ Proceed with registering this device as a trusted device
registerDeviceAsTrusted();
err => alert('Error', err),
const registerDeviceAsTrusted = async () => {
let cotter = new Cotter(API_KEY_ID);
const user = await cotter.getLoggedInUser();
resp => console.log('Success', resp),
err => console.log('Error', err),