Register or login a user using passkeys in React Native
Register a new user with a passkey
To create a new user account with a passkey, provide the user’s email address or phone number to Passage.registerWithPasskey(). View a full registration implementation on Github.
constregister=async (identifier:string) => {try {// Register user awaitPassage.registerWithPasskey(identifier);// Retrieve new user infoconstuser=awaitPassage.getCurrentUser(); } catch (error) {if (error instanceofPassageError&&error.code ===PassageErrorCode.UserCancelled) {// User cancelled native passkey prompt } else {// Optional: Passkey registration failed, try fallback authentication methodsawaitfallbackRegister(identifier); } } };
Optional: Registration Fallback Authentication
If passkey registration fails, users can be provided with a fallback authentication method. Learn more about registration fallback options here.
constfallbackRegister=async (identifier:string) => {try {// Retrieve app information to check fallback settingsconstappInfo=awaitPassage.getAppInfo();if (appInfo.authFallbackMethod ===AllowedFallbackAuth.LoginCode) {// Register with OTPconstotpId=awaitPassage.newRegisterOneTimePasscode(identifier); } elseif (appInfo.authFallbackMethod ===AllowedFallbackAuth.MagicLink) {// Register with Magic LinkconstmagicLinkId=awaitPassage.newRegisterMagicLink(identifier); } } catch (error) {// Handle error } };
Log in an existing user with a passkey
To authenticate an existing user with their passkey, pass the user’s email address or phone number to Passage.loginWithPasskey(). View a full registration implementation on Github.