Add Email/Phone Verification
Last updated
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),
);
};
...
}