Passkey Authentication

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.

const passage = new Passage('APP_ID');
 
const register = async (identifier: string) => {
    try {
        // Register user
        await passage.registerWithPasskey(identifier);
 
        // Retrieve new user info
        const user = await passage.getCurrentUser();
    } catch (error) {
        if (error instanceof PassageError && error.code === PassageErrorCode.UserCancelled) {
            // User cancelled native passkey prompt
        } else {
            // Optional: Passkey registration failed, try email or SMS registration instead.
        }
    }
};

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.

const login = async (identifier: string) => {
    try {
        // Login user
        await passage.loginWithPasskey(identifier);
 
        // Retrieve logged in user info
        const user = await passage.getCurrentUser();
        setCurrentUser(user);
    } catch (error) {
        if (error instanceof PassageError && error.code === PassageErrorCode.UserCancelled) {
            // User cancelled native passkey prompt
        } else {
            if (identifier.length) {
                // Optional: Passkey login failed, try fallback email or SMS login instead.
            }
        }
    }
};