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.passkey.register(). View a full registration implementation on Github.

const passage = new Passage('APP_ID');
 
const register = async (identifier: string) => {
    try {
        // Register user
        await passage.passkey.register(identifier);
 
        // Retrieve new user info
        const user = await passage.currentUser.userInfo();
    } 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.passkey.login(). View a full registration implementation on Github.

const login = async (identifier: string) => {
    try {
        // Login user
        await passage.passkey.login(identifier);
 
        // Retrieve logged in user info
        const user = await passage.currentUser.userInfo();
        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.
            }
        }
    }
};