UNPKG

@passageidentity/passage-react-native

Version:

Passkey Complete for React Native - Go completely passwordless with a standalone auth solution in your React Native app with Passage by 1Password

56 lines (53 loc) 2.09 kB
"use strict"; import { Platform } from 'react-native'; import { PassageError, PassageReactNative } from "../shared/index.js"; /** * PassagePasskey class contains functions that use passkeys for authentication. */ export class PassagePasskey { /** * Registers a new user with a passkey. Will throw an error if the user has already logged into their account at lesst once. * @param {string} identifier * @param {PasskeyCreationOptions | undefined} options * @returns {AuthResult} The authentication token, redirect URL, and refresh token, if configured for the application. */ async register(identifier, options) { try { const result = await PassageReactNative.passkeyRegister(identifier, options || null); const parsedResult = JSON.parse(result); return parsedResult; } catch (error) { throw new PassageError(error.code, error.message); } } /** * Logs in an existing user with a passkey. Will throw an error if the user does not exist, has no passkeys, or if the operation is cancelled with an abort signal. * If no identifier is provided, the user will be prompted to select an identifier, formally known as WebAuthn discoverable credentials. * @param {string} identifier * @returns {AuthResult} The authentication token, redirect URL, and refresh token, if configured for the application. */ async login(identifier) { try { const result = await PassageReactNative.passkeyLogin(identifier || null); const parsedResult = JSON.parse(result); return parsedResult; } catch (error) { throw new PassageError(error.code, error.message); } } /** * Checks if the user's device supports passkeys. */ isSupported() { if (Platform.OS === 'ios') { const iosVersion = parseFloat(Platform.Version); return iosVersion >= 16; } else if (Platform.OS === 'android') { const androidVersion = Platform.Version; return androidVersion >= 28; } else { return false; // Unsupported platform } } } //# sourceMappingURL=PassagePasskey.js.map